Integrate with LWA by Using Buy with Prime UI Library

📘

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.

The Buy with Prime UI library offers a low-code solution that provides sign-in functionality through Login with Amazon (LWA). When you use the UI library, you don't need to build your own UI components that initiate the sign-in flow. Instead, you populate a pre-built delivery card component.

Delivery cards display shopper-level information such as the shopper’s name, a delivery estimate, the number of items that are eligible for Buy with Prime, and a sign-in link to let the shopper sign in using their Amazon account credentials. The UI library supports both redirection and pop-ups for sign-in.

Buy with Prime Delivery Card

Delivery Card

This topic lists your LWA integration tasks if you choose to use the UI library. If you want to use your own UI components, you can integrate with LWA directly or by using an LWA SDK instead. 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.

TaskRequired?Link to Details
Set up an LWA security profile and add the static URL as an Allowed Return URL in the security profile.YesSet up an LWA security profile
Add the Buy with Prime UI library delivery-card component to the page with the static URL. Set the redirectUrl in the LWAConfig object to the static URL.YesAdd Buy with Prime UI components to a web page
After LWA redirects the shopper back to the static URL (redirectUrl), extract the authorization code, scope, and state from the query parameters and validate the state.YesExtract information from the redirected URL
Call the LWA token endpoint to get an access token and refresh token. Extract the access token and refresh token from the response. Save the refresh token in the backend session data so that you can use it to request a new access token when the access token expires.YesSend an access token request
Call the LWA customer profile endpoint to get shopper data.NoSend a request for shopper data
Use the access token as the shopper identity token as an input parameter to Buy with Prime operations.NoCreate a delivery preview with the shopper's Amazon identity (as an example)

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.

TaskRequired?Link to Details
Set up a redirect handler URL.YesSet up a redirect handler URL
Set up an LWA security profile and add the redirect handler URL as an Allowed Return URL in the security profile.YesSet up an LWA security profile
Add the Buy with Prime UI library delivery-card component to the page with the dynamic URL. Set the redirectUrl in the LWAConfig object to the redirect handler URL.YesAdd Buy with Prime UI components to a web page
After LWA redirects the shopper back to the redirect handler URL (redirectUrl), extract the authorization code, scope, and state from the query parameters and validate the state.YesExtract information from the redirected URL
Call the LWA token endpoint to get an access token and refresh token. Extract the access token and refresh token from the response. Save the refresh token in the backend session data so that you can use it to request a new access token when the access token expires.YesSend an access token request
Redirect the shopper to the dynamic URL (the page the shopper was on when they clicked the sign-in link). You can find the dynamic URL from the state when you extract the state from the redirected URL.YesExtract information from the redirected URL
Call the LWA customer profile endpoint to get shopper data.NoSend a request for shopper data
Use the access token as the shopper identity token as an input parameter to Buy with Prime operations.NoCreate a delivery preview with the shopper's Amazon identity (as an example)

Related topics