@G65434_2 I’m actually doing things a bit differently because I have the two legged approach. I have the user create a username and password for the back end system that I then manage. Once a user is saved to the database I have the server make a call to get a token from particle.io and save that to the user’s account as well. So, when the user logs in they actually log in to my system and then I retrieve their token and log them into particle with that.
Here’s a curl call for creating the new customer without a password:
curl
-X POST
-u "[org user]:[org secret]"
-d email="[customer email]"
-d no_password=true
https://api.particle.io/v1/orgs/[org slug]t/customers
To create a token for an existing customer you have to do it a little different, but it’s still just as easy:
curl
-X POST
-u "[org user]:[org secret]"
-d grant_type=client_credentials
-d scope=customer="[customer email]"
https://api.particle.io/oauth/token
Also, i usually have it try the new customer first and then fallback to creating it based on an existing customer. The reason being is that in development I try and try again with the same email and once a customer is created in particle.io you can’t really delete it, but rather get a new token.
So, once I’ve got the token that’s returned by either of the above calls, I use:
spark.login({accessToken: [access token from customer]}).then(function()
{
console.log("Logged into particle");
// See below on getting a claim code
var sap = new SoftAPSetup();
sap.setClaimCode([claim code], callback);
function callback(err, dat)
{
if(err)
{
throw err;
}
// I forget what this returns, but it should be an object with a success identifiable in it
console.log(dat);
}
});
}
Since it’s not above, here is how you get a claim code:
curl
-X POST
-d access_token=[your orgs access token / secret]
https://api.particle.io/v1/orgs/[org slug]/products/[product slug]/device_claims
You can do all of the curls above with a simple ajax call as well, I just test everything via curl first and have that better documented. Also, this code is pretty piecemealed together so let me know if something doesn’t work. Oh, also, when you do the ajax calls, you will probably have to base64 encode them and may have to include some additional headers to get them to work. I had to, but I’m doing it server side, so maybe it’s different.
Hope this helps!