How to get programmatically the oauth token after redirect?

Step 1 redirect user to Twitch
Step 2 user accepts or declines the link between clientID and application
Step 3 user returns with a ?code in the URL params (or an error)
Step 4 Obtain the code from the URL and with a curl POST request get a token

This’ll depend on the langauge you are using.

This only holds true if you are doing regular user authentication which is my assumption