Oauth using particle:particle with a legacy account

Hi,

We could use some advice on the Authorization process for using the API. We would like to find a process that works with both older "legacy" accounts and with new Particle accounts.

What works:

Create a new account. Get a token with client ID / client secret of particle:particle

curl ``https://api.particle.io/oauth/token``
-u particle:particle
-d grant_type=password
-d "``username=newaccount@ourdomain.com``"
-d "password=<yourpasswordhere>"

{"token_type":"bearer","access_token":"ffffffff897cc2b320002ddd50000c86145346a8","expires_in":7776000,"refresh_token":"ffffffffa6d1ddd00015b0e95670000d18d2b53a"}

What fails:

Using the same technique on a legacy account fails.

curl ``https://api.particle.io/oauth/token``
-u particle:particle
-d grant_type=password
-d "``username=legacyaccount@ourdomain.com``"
-d "password=<yourpasswordhere>"

{"error":"invalid_grant","error_description":"User credentials are invalid"}

Is there a way to obtain an access token without having to create a client ID / client secret in a legacy account?

That should work. What I use is slightly different and is at least worth a try to see if it makes a difference for you:

postData = {
  'client_id': 'particle',
  'client_secret': 'particle',
  'expires_in': localTokenLength,
  'grant_type': 'password',
  'password': $(passwordInputElem).val(),
  'username': $(usernameInputElem).val()
};
  • Instead of using basic auth (-u), put the client_id and client_secret in the POST body
  • Try using JSON encoding for the POST body instead of URL form encoding