Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get started
Connect with Matter
Alexa Connect Kit
Add-ons
Certify
Resources
Skip to main content
In this step, you make an authorization request to the Alexa app to get the user’s Amazon authorization code. If the Alexa app isn’t installed on the user’s mobile device, you make the request to the Login with Amazon (LWA) authorization server. The authorization code is valid for five minutes. For details about the URL parameters, see URIs and endpoints.

Get the Amazon authorization code

Follow these steps to get the user’s Amazon authorization code from the Alexa app or the LWA authorization server. To get the Amazon authorization code
  1. If your backend supports PKCE, generate the code_verifier and derive the code_challenge using SHA-256, as defined in RFC 7636, before constructing the URLs.
  2. From your app backend, construct the Alexa app URL and the LWA fallback URL with the required query parameters. Include the state for cross-site request forgery (CSRF) protection and the PKCE code_challenge and code_challenge_method parameters for enhanced security.
  3. Determine whether the Alexa app is installed on the user’s device.
  4. If the Alexa app is installed, open the Alexa app URL. If the Alexa app isn’t installed, open the LWA fallback URL in an in-app browser tab, not a native browser app.
  5. After the user acknowledges the linking request, the Alexa app or LWA redirects the user back to your app at your redirect URL with the Amazon authorization code and state.
    For details about how to handle the redirect, see the Apple guidelines on Supporting Universal Links in Your App and Android guidelines in Handling Android App Links.
  6. To prevent CSRF attacks, validate the returned state value against the value you sent in step 1. If your backend supports PKCE, use the code_verifier to validate the token endpoint, based on the stored PKCE parameters.
  7. Extract the Amazon authorization code from the redirect.

Success response

After the user acknowledges the linking request, the Alexa app or LWA redirects the user back to your app with the Amazon authorization code. The following example shows a successful redirect to your app’s Universal Link or App Link from the Alexa app.
The following example shows a successful redirect to your app’s Universal Link or App Link from LWA.
For additional details about OAuth2.0 authorization responses, see Authorization Response.

Error response

If the user denies the request or an error occurs, the Alexa app or LWA redirects the user back to your app with an error. The following example shows an error redirect:
For additional details about OAuth2.0 error responses, see Error Response.

Browser fallback

If the user’s device can’t launch your app by using the redirect URL that you configured, the Alexa app redirects the user to that same redirect URL in their default browser. Fallback might happen, for example, when one of the following occurs:
  • Universal Links or App Links aren’t enabled in your app.
  • Universal Links or App Links aren’t enabled in your app for the redirect URLs that you provided.
  • The version of the app on the user’s device is an older version that doesn’t support Universal Links or App Links.
To handle these scenarios, host a web page at the same URL as your Universal Link or App Link to receive the authorization code. When the user opens your web page, you might request them to log in so that you can get the authorization code from your service.

iOS examples

In this example, the app gets both the Alexa app URL and the LWA fallback URL.
In this example, the app opens the Alexa app URL or, the LWA fallback URL if the Alexa app isn’t installed.Note the following:
  • This example uses the UIApplication.shared.open API to open the URL with the universalLinksOnly option.
  • URLs only open when there is an app (in this case, the Alexa app) that’s configured to handle Universal Links with the universalLinksOnly option. You can therefore pass closure expressions in completionHandler to handle the case in which the Alexa app doesn’t launch (for example, the Alexa app wasn’t installed or is a version that doesn’t support Universal Links).
  • If your app isn’t able to launch the Alexa app when using the universalLinksOnly option, your app needs to get the Amazon authorization code by using LWA. For the LWA Fallback URL format, see URLs and endpoints. You can use SFAuthenticationSession on iOS 11 or ASWebAuthenticationSession on iOS 12.0 or higher. This gets the Safari user session and cookies, which avoids an extra login when the user is already logged in to Amazon.com on Safari. This will cause your app to display a window that asks the user’s consent to share website information. iOS defines the content of the consent message.
  • For iOS versions below 11.0, this example uses SFSafariViewController to send users to the LWA page. The SFSafariViewController doesn’t ask for the user’s consent to share website information; the Safari browser therefore doesn’t share cookies with the SFSafariViewController.
For websites, and as a fallback for when the Alexa app isn’t installed on the iOS device, open the LWA URL. In this example, the app opens LWA in a view controller.

Android examples

Make a request to your backend service to get both the Alexa app URL and the LWA fallback URL. You can implement this request in any way that you prefer, such as using RetroFit or any other Android library. The following code is a simple example.
In this example, the app opens the Alexa app URL or, if the Alexa app is not installed, the LWA fallback URL.Note the following:
  • This example uses the PackageManager to verify that the Alexa app is installed and to verify that the installed version of the Alexa app can handle app-to-app account linking.
  • If the Alexa app isn’t installed or can’t handle app-to-app account linking, your app must get the Amazon authorization code by using the LWA flow. For the LWA fallback URL format, see URLs and endpoints.
  • This example opens the URLs by using the Android ACTION_VIEW intent. The app-to-app URL will open in the Alexa app and the LWA fallback URL will open in the user’s default browser.

State generation example

In this example, the app generates and validates the state between the request and the response. You must validate incoming requests by using the state to prevent cross-site request forgery.

Errors

If an error occurs when your app tries to get the Amazon authorization code, the redirect_uri that the Alexa app uses to redirect the user back to your app includes an error query parameter, as described by the OAuth 2.0 specification. The Alexa app and the LWA fallback both follow the OAuth 2.0 specification, so they both return the same error codes to your app. For details about why the request to get the Amazon authorization code failed, check the error_description query parameter and the OAuth 2.0 specification description for that error code.
Error codeMessage to show to userPossible causes
invalid_requestWe are experiencing a problem connecting with Alexa to link your account. Please try again later.Request is missing state, scope, and/or response_type
unauthorized_clientWe are experiencing a problem connecting with Alexa to link your account. Please try again later.The provided client_id doesn’t have access to request consent to link the user’s account
access_deniedNone. (The user shouldn’t see an error message because they were the one who denied the access.)The user rejected the request to link their account
unsupported_response_typeWe are experiencing a problem connecting with Alexa to link your account. Please try again later.Parameter response_type isn’t equal to code
invalid_scopeWe are experiencing a problem connecting with Alexa to link your account. Please try again later.Invalid scope parameter
server_errorSorry, Alexa encountered an unexpected error while trying to link your account. Please try again.Unexpected server error
temporarily_unavailableSorry, Alexa encountered a momentary error while trying to link your account. Please try again later.Temporary server error
Last modified on October 4, 2026