After a lot of trial-and-error (and reading this forum), I've figured out the proper cURL incantations to do the following:
- Create OAuth client credentials ("MyApp")
- Create a customer for an organization (org slug: "example-corp")
- Get a scoped access token for that customer ("user-email@example.com")
- Get a device claim code for that customer (product slug: "my-product-42")
I'm writing this just to put all the information in one place to pay-it-forward.
NOTE: The response data from each step feeds into the following step.
All response examples dated 4/1/2016 (no, there are no April fools jokes embedded here).
Create OAuth Client Credentials
curl -X POST -H "Authorization: Bearer 96xxxxxxxxxxxxxxxxxxxxxx65" -d name="MyApp" -d type=installed -d organization=example-corp https://api.particle.io/v1/clients
Note: The authorization header access token was taken from Particle Build.
{
"ok": true,
"client": {
"name": "MyApp",
"type": "installed",
"id": "myapp-XXXX",
"secret": "42xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx42",
"org_id": "12xxxxxxxxxxxxxxxxxxxx34"
}
}
Create a Customer for an Organization
curl -X POST -u myapp-XXXX:42xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx42 -d email="user-email@example.com" -d password="password" https://api.particle.io/v1/orgs/example-corp/customers
{
"token_type": "bearer",
"access_token": "ebxxxxxxxxxxxxxxxxxxxxxxxxxxx7b",
"expires_in": 7776000,
"refresh_token": "2bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx58"
}
Create a Scoped Access Token for the Customer
curl -X POST -u myapp-XXXX:42xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx42 -d grant_type=client_credentials -d scope=customer=user-email@example.com https://api.particle.io/oauth/token
{
"token_type": "bearer",
"access_token": "2fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx03",
"expires_in": 7776000,
"refresh_token": "20xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx94",
"scope": "customer=user-email@example.com"
}
Get a Device Claim Code for the Customer
curl -X POST -H "Authorization: Bearer 2fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx03" https://api.particle.io/v1/orgs/example-corp/products/my-product-42/device_claims
{
"claim_code": "b/Qadxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9j0",
"device_ids": [ ]
}
And Now...
You should have everything you need at this point to put the Photon in SoftAP mode, set the new claim code, and configure the device for WiFi. Once the Photon connects to the cloud with the new claim code, the Particle cloud backend will know to associate the customer to the device.
Happy Programming!