Tutorial: Implement Voice-Forward Account Linking in Your Skill (LWA)
The following tutorial walks you through the steps to enable Alexa customers to use their voice to link their Amazon account with the account they have with your skill service.
For an overview of voice-forward account linking, see Use Voice-Forward Account Linking for Alexa Skills (LWA).
Steps to implement voice-forward account linking in your custom skill
To implement voice-forward account linking in your custom skill, take the following steps:
- Review the requirements.
- Configure your custom skill and implement account linking.
- Add voice-forward account linking to your custom skill code.
- Test your implementation.
- Certify your skill.
Step 1: Review the requirements
Review the skill, website, and customer requirements in Prerequisites.
Step 2: Configure your custom skill and implement account linking
Before you add code to link accounts by voice, you must configure your custom skill and implement traditional account linking.
To configure your custom skill and implement traditional account linking
- Sign in to the Alexa developer console and navigate to your custom skill.
- Select the Build tab.
- On the left, click TOOLS, and then click Account linking.
- Turn on Do you allow users to create an account or link to an existing account with you?.
- If you want to keep account linking as optional, turn on Allow users to enable skill without account linking.
- Turn on Allow users to link their account to your skill using voice.
Note: You can also enable voice-forward account linking by using the Update account linking information operation in the Alexa Skills Kit (ASK) Skill Management API (SMAPI).
- Fill in the rest of the account linking settings based on the information in Configure an Authorization Code Grant and save the skill.
- Implement traditional account linking. For implementation details, see Steps to Implement Account Linking in Your Skill.
Step 3: Add voice-forward account linking to your skill code
The following procedure outlines the steps to add voice-forward account linking to your custom skill code.
To add voice-forward account linking
- Implement a handler to initiate the voice-forward account linking flow by transferring control to the Amazon-owned voice-forward account linking skill.
For details, see Implement a handler to request the task to initiate voice-forward account linking.
- Implement a handler to receive a response from the Amazon-owned voice-forward account linking skill after the account linking task is complete.
For details, see Implement a handler to get the response on the task to initiate voice-forward account linking.
- As with other methods of account linking, you must include skill code to get the user's access token from Alexa's requests, validate the access token, and use it to retrieve the necessary user information from your resource server.
If your skill doesn't maintain a resource server, you can retrieve LWA
user_idby making a call to LWA.
- (Optional) If you need the customer's profile information, you must add fallback logic that calls the Customer Profile API when the voice-forward account linking flow is complete. This is because the account linking token that you obtain during the voice-forward account linking flow only has the
profile:user_idscope. To get the customer profile information, you must do the following steps:
Note: If your skill already uses LWA and accesses customers' profile information by calling LWA using the
- Get the customer's
user_idby using the access token you received from the voice-forward account linking response to call LWA.
- Use the returned
apiAccessTokento call the Customer Profile API to get the customer's information.
accessTokenobtained after the customer completes account linking in the app, you must add fallback logic to achieve the same functionality. For the fallback logic, call the Customer Profile API using the
apiAccessTokenyour skill receives in the request after successful voice-forward account linking.
- Get the customer's
Step 4: Test your implementation
Use the developer console to test your implementation in the following way.
To test your implementation
- Sign in to the Alexa developer console.
- From the skill list, select your skill.
- At the top, click the Test tab.
- On the left, under the header bar, for Skill testing is enabled in, select Development.
For details, see Test your skill in the developer console. Alternatively, you can test your skill by using the Alexa app installed on your iOS or Android mobile device. For details, see Test with the Alexa app.
- On an Echo device, launch your skill and then test it with different scenarios, such as the examples provided in User experience for voice-forward account linking.
- Test different customer account configurations, such as a test account with no voice profile, a voice profile without Personalize skills enabled, and so on.
Step 5: Certify your skill
After you build your skill and test it with your account, you can submit your skill for certification. For details about certifying a custom skill, see Certification Requirements.