- Obtained and stored the app instance’s registration ID; for more details, see Integrate Your App.
- Exchanged your OAuth client credentials for a current access token. This document describes that process.
Client credentials and access tokens
To acquire an access token, your server provides ADM servers with your OAuth client credentials. Your client credentials are assigned to you by Amazon and are two pieces of data that are unique to your app: a client_id and a client_secret value. Your servers use both pieces of your client credentials in their requests to obtain ADM access tokens. For information about how to get your client credentials, see Obtain Credentials. An access token is short-lived metadata that authenticates your server’s identity to ADM, so that you can send messages. When you send a message using ADM, that message request must include an access token. Although a server only uses a single access token at any given time, you must obtain a new access token when an old one expires. Also, although it is possible to share an access token across multiple servers, it is typically more convenient for each of your servers to obtain their own access token and independently request, track, and use it for sending messages.Request format
Your servers obtain their access tokens by providing your client credentials in a request call to ADM servers. You can use this same request to acquire an initial access token or to obtain a new one when a prior access token has expired. To obtain an access token, your server issues a POST request on an HTTPS connection. The request looks similar to this:Response format
After successfully receiving and interpreting your POST request message, ADM sends your server an HTTP response message that looks similar to this:| Header | Description | Example |
|---|---|---|
X-Amzn-RequestId | A value created by ADM that uniquely identifies the request. In the unlikely event that you have problems with ADM, Amazon can use this value to troubleshoot the problem. | X-Amzn-RequestId: <hexidecimal request ID> |
Content-Type | The content type of the resource: application/json | Content-Type: application/json |
| Parameter | Description | Example |
|---|---|---|
access_token | An access token that must be used for all enqueue requests. | "access_token":"<hexidecimal access token>" |
expires_in | The duration in seconds of the access token lifetime. For example, the value “3600” denotes that the access token expires in one hour from the time the response was generated. | "expires_in":3600 |
token_type | The type of the token issued. One of the supported token types. Currently only “Bearer” tokens are supported. | "token_type":"Bearer" |
scope | The scope specified in the access token request. Value will be messaging:push. | "scope":"messaging:push" |
JSONObject:
reason: The reason the request was not accepted.
| Code | Description | Example |
|---|---|---|
400 | Reasons for this response include: * The content type is not supported by the authorization server. In other words, it is not application/x-www-form-urlencoded. * The request is missing a required parameter: client_id, client_secret, scope, grant-type. * The request is otherwise malformed. * ADM has not been enabled for your security profile. See Obtain Credentials. | INVALID_REQUEST |
400 | The client is not authorized for the requested operation. | UNAUTHORIZED_CLIENT |
400 | The grant type is not supported by the authorization server. In other words, it is not client_credentials. | UNSUPPORTED_GRANT_TYPE |
400 | The requested scope is invalid. In other words, it is not messaging:push. | INVALID_SCOPE |
401 | The client authentication failed. | INVALID_CLIENT |
500 | There was an internal server error. The requester can retry the request. | SERVER_ERROR |
503 | The server is temporarily unavailable. The requester must retry later honoring the Retry-After header included in the response. See the HTTP/1.1 specification, section 14.37, for possible formats for the Retry-After value. | SERVICE_UNAVAILABLE |

