Integrate with LWA by Using an LWA SDK
Important
The Buy with Prime API is offered as a preview and might change as we receive feedback and iterate on the interfaces. We are sharing this early documentation to help you learn about the Buy with Prime API as we write and iterate on the content.
This topic lists your Login with Amazon (LWA) integration tasks if you choose to use an LWA SDK to customize the Buy with Prime shopper experience on your site. LWA offers three SDKs:
LWA SDKs focus solely on sign-in functionality and don't include pre-built UI components. LWA SDKs help you build the authorization request, which makes it easier to build well-formed requests compared to directly using URL query parameters.
LWA SDKs support both redirection and pop-up for sign-in. LWA SDKs also support features such as rendering authentication and authorization screens in pop-up windows, which enable you to provide a Buy with Prime sign-in experience for shoppers.
If you want pre-built UI components, integrate with LWA by using Buy with Prime UI library instead. If you don't want pre-built UI components and you want the most flexibility, you can also integrate with LWA directly. For details, see Use Login with Amazon for Shopper Identity.
Static versus dynamic redirection
Your integration tasks depend on whether you put the sign-in link on static URLs or dynamic URLs, so this topic contains a section for each type.
- A static URL doesn't have any parameters. An example is
https://www.example.com/checkout
. - A dynamic URL has parameters that change. For example, a product detail page might have a product ID in the URL (
https://www.example.com/product/red-shirt-1
) and a cart page might have a cart ID in the URL (https://www.example.com/cart/cart-id
).
For the full authentication flow in each case, see LWA Authentication Flow.
Integration tasks if you use static redirection
The following table shows the back-end tasks to implement if you put the sign-in link on pages with static URLs.
Task | Required? | Link to Details |
---|---|---|
Set up an LWA security profile and add the static URL as an Allowed Return URL in the security profile. | Yes | Set up an LWA security profile |
Add an LWA SDK to the page with the static URL. | Yes | Add the Login with Amazon SDK for JavaScript in the LWA documentation. |
Add a sign-in link to the page with the static URL and add LWA SDK code to make an authorization request, with the static URL in the next parameter. | Yes | Server Apps, Browser-Based Apps, and authorize in the LWA documentation. |
Add LWA SDK code to make an access token request. | Yes | retrieveToken in the LWA documentation. |
Add LWA SDK code to get shopper data. | No | retrieveProfile in the LWA documentation. |
Use the access token as the shopper identity token as an input parameter to Buy with Prime operations. | No | Create a delivery preview with the shopper's Amazon identity (as an example) |
Use the LWA SDK to log the shopper out of LWA on your site, which clears the session tokens that LWA maintains. By design, the shopper isn't signed out of amazon.com. | Yes | Log Out Users in the LWA documentation. |
After logging the shopper out of LWA, clean the state that you maintain for the shopper on your site. | Yes | On your site, delete the LWA access tokens associated with the shopper, and remove their profile information from your cache, local, or session storage. If your site doesn’t support account linking, delete the LWA refresh tokens associated with the shopper. |
Integration tasks if you use dynamic redirection
The following table shows the back-end tasks to implement if you put the sign-in link on pages with dynamic URLs.
Task | Required? | Link to Details |
---|---|---|
Set up a redirect handler URL. | Yes | Set up a redirect handler URL in this documentation or Dynamically Redirect Users in the LWA documentation. |
Set up an LWA security profile and add the redirect handler URL as an Allowed Return URL in the security profile. | Yes | Set up an LWA security profile |
Add an LWA SDK to the page with the dynamic URL. | Yes | Add the Login with Amazon SDK for JavaScript in the LWA documentation. |
Add a sign-in link to the page with the dynamic URL and add LWA SDK code to make an authorization request, with the redirect handler URL in the next parameter and the dynamic URL in the state parameter. | Yes | Server Apps, Browser-Based Apps, Calculating the State Parameter and authorize in the LWA documentation. |
After LWA redirects the shopper back to the dynamic URL (redirect handler URL), extract the authorization code , scope , and state from the query parameters and validate the state . | Yes | Extract information from the redirected URL |
Re-render the dynamic URL (e.g., product detail page) to the shopper, now with the state as a query parameter. | Yes | Re-render the dynamic URL with the state |
Add LWA SDK code to make an access token request. | No | retrieveToken in the LWA documentation. |
Add LWA SDK code to get shopper data. | No | retrieveProfile in the LWA documentation. |
Use the access token as the shopper identity token as an input parameter to Buy with Prime operations. | No | Create a delivery preview with the shopper's Amazon identity (as an example) |
Use the LWA SDK to log the shopper out of LWA on your site, which clears the session tokens that LWA maintains. By design, the shopper isn't signed out of amazon.com. | Yes | Log Out Users in the LWA documentation. |
After logging the shopper out of LWA, clean the state that you maintain for the shopper on your site. | Yes | On your site, delete the LWA access tokens associated with the shopper, and remove their profile information from your cache, local, or session storage. If your site doesn’t support account linking, delete the LWA refresh tokens associated with the shopper. |
Related topics
Updated about 4 hours ago