Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Use Login With Amazon to Link A User Account to My Skill?

I am having a hard time getting this to work by following along with Amazon's Alexa documentation. I'm running aground on Account Linking because I can't figure out how to get Login with Amazon (LWA) to ask for alexa::skills:account_linking scope.

I've included the Amazon API library in my application and set that all up correctly and I'm invoking the process using the (globally available) amazon object as follows (typescript):

    const options: any = {};
    options.scope = ['profile', 'alexa::skills:account_linking'];
    options.scope_data = {
        profile : {essential: false}
    };    
    options.response_type = 'code';

    const self = this;
    amazon.Login.authorize(options, (response) => {
      if (!response || !response.code) {
        throw { error: response };
      }

      // ... send the response code to my server 
      // ... to be exchanged for bearer and refresh tokens
    });

What I would expect to happen from that is a popup Amazon login process to be spawned which (1) has the user log in to Amazon, and (2) collects the user's consent to link their Amazon account to my Alexa skill (i.e. linked to my credentialed hosted service), so that we get back (in the browser) an authorization code that we can exchange (on our server) for bearer and refresh tokens to act on behalf of the user.

The problem is, that code above immediately fails and never pops up a process. The message that is thrown says: "An unknown scope was requested". If I remove the 'alexa::skills:account_linking' string from the options.scope array, I get to an Amazon login screen, and if I log in to Amazon, my server does get an authorization code, etc. But no Account Linking has taken place, so I'm stuck.

I've tried to reconcile this documentation (which also talks about including a Skill ID somehow), with this documentation but I'm just not seeing how to make it work. Can anyone please help point me in the right direction about what I'm doing wrong here? It must be something pretty fundamental.

like image 772
vicatcu Avatar asked Nov 06 '22 12:11

vicatcu


1 Answers

If your goal is to use Login with Amazon for account linking only for the skill and to not store the tokens on your own server, you can set up the skill and Login with Amazon with the below configurations. The advantage of this approach is that you don't need to stand up your own web server to just handle the LwA flow. This approach also handles all the flow out of the box, including refreshing tokens.

If you're using these tokens for another purpose, you may want to look into something like AWS Cognito to simplify the process.

Skill Account Linking Configuration

Replace Your Client ID with the LwA Client ID, replace Your Secret with the LwA Client Secret, and copy your redirect URIs

Skill Account Linking Configuration

LwA Configuration

Paste your Alexa redirect URLs here. These will be specific to your vendor account so it's important to have the right ones.

Login with Amazon Configuration

Source: This is what I do for my Aberto Sonorus skill: https://www.amazon.com/WBPhoto-Aberto-Sonorus/dp/B078W199Z3 (edited screenshots attached)

like image 68
wblaschko Avatar answered Nov 15 '22 05:11

wblaschko