# Authentication in php with oAuth

**URL:** <https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149>\
**Category:** API\
**Created:** [May 1, 2015, 7:51pm UTC](https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149 "2015-05-01T19:51:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielps1](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@danielps1](https://discuss.dev.twitch.com/u/danielps1)\
**Post date:** [May 1, 2015, 7:51pm UTC](https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149/1 "2015-05-01T19:51:30Z")

</div>

I’m totally new to APIs in general only have some php experience.

I just basicly need a button to login via twitch and then I can read their username.

This isn’t secure information so there isn’t a token needed.

But as far as I understand correctly, I have to do it anyways to get a token and then get the username.

My problem is twitch spits out

```
{
"error": "Bad Request",
"status": 400,
"message": "client does not exist"
}

```

I used this url out of a tutorial

```
https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=[clientid]&redirect_uri=[http://localhost:8000/]&scope=[user_read]

```

clientid is obviously my Application ID that I have censored

And here is the tutorial I was following  
[https://github.com/justintv/Twitch-API/blob/master/authentication.md#auth-code](https://github.com/justintv/Twitch-API/blob/master/authentication.md#auth-code)

Any help would be really cool!

---

<div class="post-metadata">

**Author:** ![mb3364](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mb3364](https://discuss.dev.twitch.com/u/mb3364)\
**Post date:** [May 2, 2015, 12:01am UTC](https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149/2 "2015-05-02T00:01:56Z")

</div>

Hey, remove the `[]` brackets from the URL.

For example:  
`https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=clientid&redirect_uri=http://localhost:8000/&scope=user_read`

---

<div class="post-metadata">

**Author:** ![danielps1](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@danielps1](https://discuss.dev.twitch.com/u/danielps1)\
**Post date:** [May 2, 2015, 11:09am UTC](https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149/3 "2015-05-02T11:09:23Z")

</div>

Thanks just a quick 2nd question.

The token appears in the url after you get redirected can I use that token in the URL?

I have it in php with the function `$_SERVER['QUERY_STRING']`

but the offical API documentation says I need to use

```
POST https://api.twitch.tv/kraken/oauth2/token

```

But I don’t know how to use this “post”

---

<div class="post-metadata">

**Author:** ![mb3364](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mb3364](https://discuss.dev.twitch.com/u/mb3364)\
**Post date:** [May 2, 2015, 10:29pm UTC](https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149/4 "2015-05-02T22:29:50Z")

</div>

You will need to make the POST request as specified in the Authentication doc. For background you can read about POST here: [http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html) . Essentially it is the method data is sent from forms on websites to the server.

I did a quick google search for sending a POST request from PHP and found: [https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php](https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php)

If you are using a framework, I would suggest looking into a more specific way to do it from within that framework as it may be cleaner and in better practice.

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [June 1, 2015, 10:30pm UTC](https://discuss.dev.twitch.com/t/authentication-in-php-with-oauth/2149/5 "2015-06-01T22:30:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
