Authorization codes are one-use tokens. When used to retrieve an access_token they return a refresh_token that may be used to retrieve the next access_token. The following section takes you through retrieving your first refresh_token.
Initial request
The first time you request a token, you’ll need the following:
- Application’s security profile client_id
- Application’s security profile client_secret
- Application’s registered redirect_uri
- Application authorization code previously created
- The grant_type to use, which should be
To request a token:
- Enter the client_id, client_secret, authorization_code, and grant_type as URL-encoded form data.
- Make an HTTP request.
The curl command to generate tokens from authorization_code is shown in the following example.curl --request POST \ --url https://api.amazon.com/auth/o2/token \ --header 'content-type: application/x-www-form-urlencoded' \ --data 'grant_type=authorization_code' \ --data 'code=ANxuOkcwmzUHvimjMTAX' --data 'client_id=amzn1.application-oa2-client.20534a91be57487e9c3547dada8a7394' \ --data 'client_secret=c007c411c9657dde807a11a96a3cfd8a2972f9599ac28de241675832f63cac05' \ --data 'redirect_uri=https://development.amazon.com/ap/ibatest'
Two tokens are returned, an access_token and a refresh_token.{ "access_token": "Atza|IwEBIPSxTCdGGC-xL-ywFib_lJfg-D7d435Jw739GWa3xy6dHJxXqy2EwddQkIchiDNiqa4kFJ4iTv_ WcFCPoQ6qNvEIxlwDU9yxadZon9-fWh42Qt-hqB8kL6X1iFaDVsBjt3DSgfbe5DYOn_NCOF_r0Z0c3ArA1ft1g082lKYDC4Lo_qYy VhRO0yn3cMEjzvgmiSJREtAg69Ey_7bfbqFycIv4IrPd45RIEnrHR1ovac66U8zeqXMjV6MLE2I-Q_34BmSM3WfdT8DUFsoRtsoZi rFAXPZT5BLrUl4iVUsNF3hr8w4-JIw63VG8KpNlg8jsgB8VQUSJe-vhQfGvukIKAkeQ-iReWSd-_8f2XfhZlhNuBBNu0LnpeCPdu7 e7zJqzgZC3_oDE8wNDd89Z4qHn3fr7", "refresh_token": "Atzr|IwEBIDxSD_pLhlNA0Jn8UbGDhcsxEt70JizgXXXaITEwstKSsLO007_pNcQ13H6umgVcLvPiXthZL4 UJnHv8tYAqbVVnH7CUanaA4MDwY9JMf-CVHltiDYm7uv6lTuBIVe5IgXPvyctGyuu8SQxPtKEgejF0Iyoy_7uWZ8l185XU426Bw1U E7CfifWl8NE2a13WmBFZJTnvjj2hkwCEnTAvUDRYHW7inp7REnKMU66EeX36Vv5ZrPl2YAgZe3xwm2bFsC5v8ytY_sBX6nN79AJ7j -wYY4EehyCFBgYNqXLLUaGPA4IBFRw3UW5XwR2EJ-VSloGucgINgzIS9tCVK4qg_hkU-XTnuEFOm-P9M4bAvL5oGXQ", "token_type": "bearer", "expires_in": 3600 }
Ordinary token requests
Each subsequent call to get a new short-lived token must use a grant_type of refresh_token and include the refresh_token. Your application will request the following steps each time it begins a new session. This procedure uses the refresh_token combined with the existing secrets to issue a new short-lived access_token.
- Enter the client_id, client_secret, redirect_uri, authorization_code, and grant_type as URL-encoded form data.
Make an HTTP request (using either curl or Reference Implementation application).
Use the following curl command to generate access tokens using a refresh token:curl --request POST \ --url https://api.amazon.com/auth/o2/token \ --header 'content-type: application/x-www-form-urlencoded' \ --data 'grant_type=refresh_token' \ --data 'client_id=amzn1.application-oa2-client.20534a91be57487e9c3547dada8a7394' \ --data 'client_secret=c007c411c9657dde807a11a96a3cfd8a2972f9599ac28de241675832f63cac05' \ --data 'refresh_token=Atzr|IwEBIPw8sQi6vSq67a0QeWDjRp4DJusAHG9kg-707e9PVbCbFTD3mU3H9ztkXppkSfeIgGsq d4zDnwr5y5hbFZvqyEQPsPRPNspT4cyWNhS6teaQsgyQa6CDTEejwYksDC4rQCi77p67zAkVzh6vHAuVJwkmaXH8IFFouRvR5gp qrffASpNv1eZwLTyqJzMNyU2CNJrIgurqJmByJN3u-smxLkshqMej0anoykw8qyNTmNxrzYRZJR2KdZLH6Kcw9mO41zHJKVWKi_ My4_bevVGd8viCGUeXeaRgOONI-GtGoQOZV7NwERLFkjT8Imw_yu4AeZ9lXEomFTy61RhieWvpxJmHNDb6MRuJcywFhx-h2fw1I jxP-W3J6HuVME69UMdapNkgk3bfgpWCsfkxDP3Qq1MddDkYvoTuJPAtqq12X4hvmlM1OZWsy8uG0Pckb9S3D1rh4g06pWcx-VaW GXQr2hbP58DWWQYIbLW-kZHD0eakoqNdrOtj56IMZZTz7RAPdmHiiHScDkgu6PyiBFBDBV7V'
Two tokens are returned, an access_token and a refresh_token.
{ "access_token": "Atza|IwEBIPSxTCdGGC-xL-ywFib_lJfg-D7d435Jw739GWa3xy6dHJxXqy2EwddQkIchiDNiqa4kFJ4iTv_ WcFCPoQ6qNvEIxlwDU9yxadZon9-fWh42Qt-hqB8kL6X1iFaDVsBjt3DSgfbe5DYOn_NCOF_r0Z0c3ArA1ft1g082lKYDC4Lo_qYy VhRO0yn3cMEjzvgmiSJREtAg69Ey_7bfbqFycIv4IrPd45RIEnrHR1ovac66U8zeqXMjV6MLE2I-Q_34BmSM3WfdT8DUFsoRtsoZi rFAXPZT5BLrUl4iVUsNF3hr8w4-JIw63VG8KpNlg8jsgB8VQUSJe-vhQfGvukIKAkeQ-iReWSd-_8f2XfhZlhNuBBNu0LnpeCPdu7 e7zJqzgZC3_oDE8wNDd89Z4qHn3fr7", "refresh_token": "Atzr|IwEBIDxSD_pLhlNA0Jn8UbGDhcsxEt70JizgXXXaITEwstKSsLO007_pNcQ13H6umgVcLvPiXthZL4 UJnHv8tYAqbVVnH7CUanaA4MDwY9JMf-CVHltiDYm7uv6lTuBIVe5IgXPvyctGyuu8SQxPtKEgejF0Iyoy_7uWZ8l185XU426Bw1U E7CfifWl8NE2a13WmBFZJTnvjj2hkwCEnTAvUDRYHW7inp7REnKMU66EeX36Vv5ZrPl2YAgZe3xwm2bFsC5v8ytY_sBX6nN79AJ7j -wYY4EehyCFBgYNqXLLUaGPA4IBFRw3UW5XwR2EJ-VSloGucgINgzIS9tCVK4qg_hkU-XTnuEFOm-P9M4bAvL5oGXQ", "token_type": "bearer", "expires_in": 3600 }
Access tokens and refresh tokens
access_token: This short-lived token is included in HTTP requests to the API. Although short-lived, it’s sensitive, so don’t share it. New access_tokens can easily be generated.
refresh_token: This indefinite token is used by the client to request all subsequent tokens and is also sensitive. When combined with the client_id and client_secret for your application, you can use the refresh_token to create more access_tokens.
Note: The OAuth2 spec allows the refresh_token to change each time it’s used. While the Amazon implementation doesn’t always do so, you should assume that it could happen any time, and use a mutable secrets store for this value.