Issue Generating OAuth User Token


#1

I have a chat bot that I want to be able to create clips but I am having trouble generating a User OAuth token for it.

Currently I am just authorizing the bot by navigating to this page in my web browser.

https://id.twitch.tv/oauth2/authorize?client_id=8be7hguk2ntew88z3s2cn3ze98vc2x&redirect_uri=http://localhost&response_type=token&scope=clips:edit&force_verify=true

And copying the code received into this

public static void Main(string[] args) {

            string id = "8be7hguk2ntew88z3s2cn3ze98vc2x";
            string secret = "secret";
            string code = "code";

            HttpClient client = new HttpClient();
            var responsetask = client.PostAsync(
                "https://id.twitch.tv/oauth2/token?client_id="+id+"&client_secret="+secret+"&code="+code+"&grant_type=authorization_code&redirect_uri=http://localhost", new StringContent(""));

            responsetask.Wait();

            var response_string = responsetask.Result.Content.ReadAsStringAsync();

            response_string.Wait();

            Console.WriteLine(response_string.Result);

            File.WriteAllText("C:/Users/User/Desktop/Output.txt", response_string.Result);
            client.Dispose();

            Console.ReadKey();
}

But I keep receiving this error code {“status”:400,“message”:“Invalid authorization code”}
If anyone knows why this is happening or has another less stupid way I can get the code locally I would appreciate it


#2

This usually means the code has been used twice.

But the URL you created is for implicit auth. (response_type token)

Implicit doesn’t need the second step that you are trying to do as it returns the access_token from the start

These sort of tokens cannot be renewed, so you should probably be using

response_type code

Which does need the second step you are trying to do


#3

Yeah I am using that process I copied the wrong url at first “https://id.twitch.tv/oauth2/authorize?client_id=8be7hguk2ntew88z3s2cn3ze98vc2x&redirect_uri=http://localhost&response_type=token&scope=clips:edit&force_verify=true” is the url im actually using. Wait those links both have the same URL do they not?


#4

This is implicit auth you don’t need the second step

response_type auth type refresh step two? You are Using
token implicit auth can’t no second step Yes
code “normal” auth can needs second step No

#5

Okay but I am trying to get a code that can refresh and I’m doing so by continuing to the second step in that program am I not? I feel like im fundamentally misunderstanding something here.


#6

Should be code not token


#7

I apologize for being so dense I haven’t slept in 2 days. I got the response I expected now


#8

You should sleep

And s’all good it happens


#9

I have Real bad Insomnia so it’s not really a choice. But thanks for your help