Example Web Setup App (Simple Authentication)

@G65434_2 - To tease apart OAuth setup issues from request construction issues, have you tried creating customers using the curl request templates from the docs? I assume you’re using simple auth, which means you probably created a client using a request like this:

$ curl -X POST -H "Authorization: Bearer [access_token]" -d name=[name] -d type=installed -d organization=[org-slug] -d scope=create_customer https://api.particle.io/v1/clients

I created two clients, one with -d scope=create_customer and one without. Then I ran this for each:

$ curl -X POST -u "[client_id]:[client_secret]" -d email=[email] -d no_password=true https://api.particle.io/v1/orgs/[org-slug]/customers

For the one without the scope, I got the following error:

{
  "ok": false,
  "code": 400,
  "error": {
    "name": "OAuth2Error",
    "message": "No valid scopes",
    "stack": "Error: No valid scopes\n    at saveAccessToken (/spark/api_service/releases/4652fd0e26bcc03a81d0d06f2e3bb73178d0be37/lib/OAuth2ServerModel.js:131:19)\n    at Grant.saveAccessToken (/spark/api_service/shared/vendor/node_modules/oauth2-server/lib/grant.js:420:14)\n    at run (/spark/api_service/shared/vendor/node_modules/oauth2-server/lib/runner.js:15:14)\n    at /spark/api_service/shared/vendor/node_modules/oauth2-server/lib/runner.js:17:7\n    at /spark/api_service/shared/vendor/node_modules/oauth2-server/lib/grant.js:395:3\n    at OAuth2ServerModel.generateExpiresTime (/spark/api_service/releases/4652fd0e26bcc03a81d0d06f2e3bb73178d0be37/lib/OAuth2ServerModel.js:246:3)\n    at Grant.generateExpiresTime (/spark/api_service/shared/vendor/node_modules/oauth2-server/lib/grant.js:387:13)\n    at run (/spark/api_service/shared/vendor/node_modules/oauth2-server/lib/runner.js:15:14)\n    at /spark/api_service/shared/vendor/node_modules/oauth2-server/lib/runner.js:17:7\n    at /spark/api_service/shared/vendor/node_modules/oauth2-server/lib/grant.js:375:5\n    at Object.ondone (/spark/api_service/shared/vendor/node_modules/oauth2-server/lib/token.js:55:5)",
    "headers": {
      "Cache-Control": "no-store",
      "Pragma": "no-cache"
    },
    "code": 503,
    "error": "server_error",
    "error_description": "server_error"
  }
}

Re-running that exact line, I saw a successful message indicating that the request still somehow succeeded:

{
  "ok": false,
  "code": 400,
  "error": "customer_exists"
}

Running that request for the client without the scope, I immediately received a success response with an access token. So basically, I think there may be something up with simple authentication, though it’s worth noting that the requests above were actually from the docs for two-legged auth. There may be a good reason that simple auth says “Specific implementation details coming soon”.

1 Like