Generate a Public OAuth Token
Generate a Public OAuth Token
An access token is required for applications to access Cortex API. To use the API or build an application that doesn't require the end user to create an account or authenticate, the client application should request a public access token. This access token enables access to resources that don't require a registered account.
Requesting an access token
Below is an example of the authentication workflow for requesting a PUBLIC access token from the client application's perspective.
- Construct a POST request to the OAuth2 Resource and set the content-type to application/x-www-form-urlencoded
POST http://www.myapi.net/oauth2/tokens Content-Type: application/x-www-form-urlencoded
- Include the following parameters in the request body
grant_type=password&scope=mobee&role=PUBLIC
Note: Username and Password not UsedUsernames and Passwords are not used in this scenario. To generate a token to access resources that require a registered account, see Authenticate a customer.
- The Cortex API authenticates the request and returns either a success or failure HTTP response. Successful authentication returns the following HTTP response:
{ "access_token": "a9256d79-9273-4820-b45d-587f90d1dc9b", "token_type":"bearer", "expires_in": 359, "scope" : "MOBEE", "role": "PUBLIC" }
Unsuccessful authentication returns a 401 status code and an error message.
Using an access token
Once a token is granted, all subsequent requests to Cortex API must include the access token in an Authorization request header. If the access token is invalid, does not exist in the Authorization request header, or the user does not have the authority to access a resource, Cortex API returns a 401 status code
Add the access token to your request headers as shown in the example below:
Content-Type: application/json Authorization: Bearer a9256d79-9273-4820-b45d-587f90d1dc9b
You must use Bearer in the Authorization header. This is an OAuth 2.0 standard.