# OAuth authorization code flow isnt working

**URL:** <https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665>\
**Category:** API\
**Created:** [December 27, 2020, 4:38pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665 "2020-12-27T16:38:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 4:38pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/1 "2020-12-27T16:38:18Z")

</div>

The OAuth authorization code flow isnt working! I made all things who write there in the docs!

[https://id.twitch.tv/oauth2/token?client\_id=CLIENTID&client\_secret=SECRET&code=CODE&grant\_type=authorization\_code&redirect\_uri=http://localhost/connect.php](https://id.twitch.tv/oauth2/token?client_id=CLIENTID&client_secret=SECRET&code=CODE&grant_type=authorization_code&redirect_uri=http://localhost/connect.php)

But the API says 404 Page not Found! PLS Help me

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 4:39pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/2 "2020-12-27T16:39:43Z")

</div>

This is step 3 of oAuth

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

You are supposed to make a HTTP POST request to this URL, your 404 Error suggests you made a HTTP GET request instead

PHP Example: [https://github.com/BarryCarlyon/twitch\_misc/blob/master/authentication/user\_access\_generator/php/index.php#L38](https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/php/index.php#L38)  
NodeJS Example: [https://github.com/BarryCarlyon/twitch\_misc/blob/master/authentication/user\_access\_generator/nodejs/server.js#L127](https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/nodejs/server.js#L127)

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 4:53pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/3 "2020-12-27T16:53:31Z")

</div>

@BarryCarlyon can you tell me what a POST and GET ís? Im new. And whats that? : [https://github.com/BarryCarlyon/twitch\_misc/blob/master/authentication/user\_access\_generator/php/index.php#L38](https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/php/index.php#L38)

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 4:55pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/4 "2020-12-27T16:55:49Z")

</div>

It’s just different ways for HTTP requests to be made and generally infer that other stuff will happen when you perform a given request

Loosely:

GET will only send “arguments” in the “URL”

POST will do either.

GET’s are repeatable  
POST’s generally are not (as different data would be POSTed each time)

POST’s also allow more/other kinds of data to be send other than the limitations of the query string that only GET allows

More reading:

> **[What is GET and POST method in HTTP and HTTPS Protocol? Answer](https://javarevisited.blogspot.com/2012/03/get-post-method-in-http-and-https.html)**
>
> A blog about Java, Programming, Algorithms, Data Structure, SQL, Linux, Database, Interview questions, and my personal experience.

> **[HTTP Methods GET vs POST](https://www.w3schools.com/tags/ref_httpmethods.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:01pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/5 "2020-12-27T17:01:33Z")

</div>

@BarryCarlyon But [https://id.twitch.tv/oauth2/token?client\_id=CLIENTID&client\_secret=SECRET&code=CODE&grant\_type=authorization\_code&redirect\_uri=http://localhost/connect.php](https://id.twitch.tv/oauth2/token?client_id=CLIENTID&client_secret=SECRET&code=CODE&grant_type=authorization_code&redirect_uri=http://localhost/connect.php) is a post, or not?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:02pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/6 "2020-12-27T17:02:50Z")

</div>

Thats jsut a URL… You didn’t declare what HTTP method you are using.

Or provide the code you are using to run your website/tool for generating access tokens

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:07pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/7 "2020-12-27T17:07:16Z")

</div>

And how I can declare what the HTTP method is? @BarryCarlyon

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:08pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/8 "2020-12-27T17:08:02Z")

</div>

> [@Diego\_Fernandez](#):
>
> And how I can declare what the HTTP method is?

In the programmingcode you have

> [@BarryCarlyon](#):
>
> provide the code you are using to run your website/tool for generating access tokens

Provide the code you are using (secrets removed) and we can take a look see.

You woriking in Node? Python? PHP? brainfuck?

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:08pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/9 "2020-12-27T17:08:53Z")

</div>

In PHP

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:09pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/10 "2020-12-27T17:09:12Z")

</div>

> <https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/php/index.php#L38>

Is a PHP example

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:11pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/11 "2020-12-27T17:11:46Z")

</div>

OK Thanks, but how can I get the code in my url? I mean this: localhost/test.php?code=1224345231356456…

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:13pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/12 "2020-12-27T17:13:21Z")

</div>

> <https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/php/index.php#L44>

Query string parameters are found in `$_GET`

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:23pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/13 "2020-12-27T17:23:47Z")

</div>

**Notice** : Undefined index: code in **C:\xampp\htdocs\connect.php** on line **10**

Line 10: ‘code’ =\> $\_GET[‘code’],

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:24pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/14 "2020-12-27T17:24:26Z")

</div>

There there is no `code` to retrieve from the Querystring

A check such as

> <https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/php/index.php#L32>

Will crush the notice

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:37pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/15 "2020-12-27T17:37:53Z")

</div>

Yes and wheres now the access key @BarryCarlyon?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:39pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/16 "2020-12-27T17:39:16Z")

</div>

Instide the response to the curl request.

It’ll need to be JSON decoded and then you can exract it from the object

My JSON Decode is here

> <https://github.com/BarryCarlyon/twitch_misc/blob/master/authentication/user_access_generator/php/index.php#L57>

Token is in `$token->access_token`

Also as shown elsewhere in my example I linked to

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:49pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/17 "2020-12-27T17:49:12Z")

</div>

But the http\_code isnt 200

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:50pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/18 "2020-12-27T17:50:08Z")

</div>

Debug your PHP code.

Spit out the response it’ll describe the error

---

<div class="post-metadata">

**Author:** ![Diego\_Fernandez](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/diego_fernandez/32/10993_2.png) [@Diego\_Fernandez](https://discuss.dev.twitch.com/u/Diego_Fernandez)\
**Post date:** [December 27, 2020, 5:52pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/19 "2020-12-27T17:52:37Z")

</div>

@BarryCarlyon **Recoverable fatal error** : Object of class stdClass could not be converted to string in **C:\xampp\htdocs\connect.php** on line **26** Sorry for my many questions xD

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [December 27, 2020, 5:53pm UTC](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665/20 "2020-12-27T17:53:02Z")

</div>

`print_r` should spit it out

[Next page](https://discuss.dev.twitch.com/t/oauth-authorization-code-flow-isnt-working/29665.md?page=2)
