# OAuth flow changed?

**URL:** <https://community.smartthings.com/t/oauth-flow-changed/19077>\
**Category:** SmartApps & Automations\
**Created:** [July 12, 2015, 8:03pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077 "2015-07-12T20:03:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JasonBSteele](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jasonbsteele/32/12986_2.png) [@JasonBSteele](https://community.smartthings.com/u/JasonBSteele)\
**Post date:** [July 12, 2015, 8:03pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/1 "2015-07-12T20:03:52Z")

</div>

Hi All,

I have documented the steps to go through the OAuth flow here:

> <https://github.com/JasonBSteele/SmartThings/blob/master/README.md>

1. Get the code  
[https://graph.api.smartthings.com/oauth/authorize](https://graph.api.smartthings.com/oauth/authorize)?  
response\_type=code&  
client\_id=MY CLIENT ID&  
scope=app&  
redirect\_uri=https%3A%2F%[2Fgraph.api.smartthings.com](http://2Fgraph.api.smartthings.com)%2Foauth%2Fcallback

2. Use the code returned to get the Access Token  
[https://graph.api.smartthings.com/oauth/token](https://graph.api.smartthings.com/oauth/token)?  
grant\_type=authorization\_code&  
client\_id=MY CLIENT ID&  
client\_secret=MY CLIENT SECRET&  
code=THE CODE&  
scope=app&  
redirect\_uri=https%3A%2F%[2Fgraph.api.smartthings.com](http://2Fgraph.api.smartthings.com)%2Foauth%2Fcallback

But this call fails with the following response:  
{“error”:“invalid\_client”,“error\_description”:“Bad client credentials”}

I’m sure this used to work, but now it fails can anyone tell me why?

(Incidentally I have managed to get OAuth2 to work in Postman using the same Client ID and Secret).

Thanks,  
Jason

---

<div class="post-metadata">

**Author:** ![joshua\_lyon](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/joshua_lyon/32/12655_2.png) [@joshua\_lyon](https://community.smartthings.com/u/joshua_lyon)\
**Post date:** [July 13, 2015, 3:17am UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/2 "2015-07-13T03:17:29Z")

</div>

Once you get the code, try swapping out the code for a token using Incognito mode in whatever browser you are logged in with. It seems that if the browser maintains session state (eg. you being logged in), it will throw the bad client credentials message you are seeing on the second step where you swap out the code for a token.

Based on your example, you might run step 1 from a normal Chrome window, then open up Chrome Incognito (Ctrl+Shift+N) and execute step 2.

* * *

Alternatively, you could open up your Chrome Developer tools, open the Resources tab, expand Cookies and select the SmartThings entry, and delete the JSESSIONID cookie between each call.

 ![](https://global.discourse-cdn.com/smartthings/original/3X/d/6/d67f99f2686c13a408bd97061eaa135eaeeae928.png)

---

<div class="post-metadata">

**Author:** ![obycode](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/obycode/32/12597_2.png) [@obycode](https://community.smartthings.com/u/obycode)\
**Post date:** [July 13, 2015, 4:50pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/3 "2015-07-13T16:50:28Z")

</div>

After talking with a SmartThings engineer, the solution that we are using for SmartRules is that when you have the code and are requesting the token, you need to add a basic authorization header, using the client ID and client secret as username and password, respectively.

---

<div class="post-metadata">

**Author:** ![slagle](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/slagle/32/16950_2.png) [@slagle](https://community.smartthings.com/u/slagle)\
**Post date:** [July 13, 2015, 5:05pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/4 "2015-07-13T17:05:43Z")

</div>

Hey guys!

Yep, the process did change a little. Official documentation coming soon to a documentation site near you.

---

<div class="post-metadata">

**Author:** ![joshua\_lyon](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/joshua_lyon/32/12655_2.png) [@joshua\_lyon](https://community.smartthings.com/u/joshua_lyon)\
**Post date:** [July 13, 2015, 5:05pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/5 "2015-07-13T17:05:48Z")

</div>

It seems odd that you would need to do that and I am curious what the reasoning is. I tested this with various tools last night and found that as long the request to swap out the code for a token is sent without the session information, then it would work every time.

Even issuing a basic HTTP GET request via raw TCP connection works fine:

```
GET /oauth/token?grant_type=authorization_code&client_id=CLIENTID&client_secret=CLIENTSECRET&code=THECODE&scope=app&redirect_uri=https%3A%2F%2Fgraph.api.smartthings.com%2Foauth%2Fcallback HTTP/1.1
Host: graph.api.smartthings.com
Cache-Control: no-cache

```

PS. I don’t recall having to open up a fresh browser session to get this to work in the past, so it does seem like something has changed. The OAuth workflow has worked for 9+ months with my Android app, SharpTools - I am effectively using fresh HTTP connections each time only adding the necessary headers when needed.

---

<div class="post-metadata">

**Author:** ![JasonBSteele](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jasonbsteele/32/12986_2.png) [@JasonBSteele](https://community.smartthings.com/u/JasonBSteele)\
**Post date:** [July 13, 2015, 6:07pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/6 "2015-07-13T18:07:56Z")

</div>

Haha - the Cookie Monster strikes again!

So I tried by closing all browser instances first, then launch a fresh one and I still got the credentials error.

Then I took your advice @joshua_lyon and created an incognito tab and this time it worked!

This is definitely something I didn’t used to have to do.

---

<div class="post-metadata">

**Author:** ![slagle](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/slagle/32/16950_2.png) [@slagle](https://community.smartthings.com/u/slagle)\
**Post date:** [July 14, 2015, 8:14pm UTC](https://community.smartthings.com/t/oauth-flow-changed/19077/7 "2015-07-14T20:14:46Z")

</div>

I’ll just leave this here 😄

> [@Changes for OAuth Access Token Requests](https://community.smartthings.com/t/changes-for-oauth-access-token-requests/19174):
>
> Hey SmartThings Developers! We recently made an update to improve the security around how we accept OAuth access token requests. The common use case for this is if you are writing a Web Services SmartApp, and need to get an access token to make requests to it. This change aligns us closer to the OAuth 2 specification (RFC 6749) and is a good improvement! It might, however, mean that the way in which you request access tokens might need to be updated. See the [docs](http://smartthings.readthedocs.org/en/latest/smartapp-web-services-developers-guide/tutorial-part2.html#get-the-api-token) for more info.
