Alexa Account Linking - "Invalid account linking credentials"

1.3k views Asked by At

I am creating an Alexa skill with account linking. I got the Linking Authorization Code and exchanged it for an Access Token. then, I tried to put all of the paramaters: code, access token, skill ID, into the Alexa Skill Activation API. I always get a massage: "Invalid account linking credentials".

    var clientServerOptions = {
        uri: `https://api.amazonalexa.com/v1/users/~current/skills/${SkillId}/enablement`,
        body: JSON.stringify({
            stage: "development",
            accountLinkRequest: {
                redirectUri: "https://api.amazon.com/auth/o2/token",
                authCode: req.body.code, //the code I got from the start
                type: "AUTH_CODE"
            }
        }),
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${req.body.access_token}` //my access token
        }
}
request(clientServerOptions, function (error, response) {
    if(error != null) {
        console.error(error);
    } else {
        console.log(response.body);
    }
    return;
});

what to do?

1

There are 1 answers

2
Sprite On

There a few mistakes I had made along the way of enabling App-App Linking (Starting from your App). Do check if you might be making anyone of these.

Mistakes -

  1. Creating a new LWA (Login with Amazon) Profile.
    You don't need a new LWA profile, you should instead use the Alexa credentials under the permissions tab on the skill page. They have the right scope (alexa::skills:account_linking) required for App-App Linking and LWA profiles cannot have this scope.

  2. Using a development version of a live skill.
    I had modified the account linking section in a development version to point to a test deployment. Although these changes are permitted in the developer console, account linking failed every time, so I created a new skill.

  3. Reusing the Alexa Auth Code.
    I had not realized that even a single bad request will invalidate the Alexa Auth Code.

  4. Logging into the wrong Alexa Account.
    When you get to the LWA screen during testing the account linking, only login with the developer credentials in which the skill is created. This is because at this point the skill is only available to the Alexa developer account and not anyone else. (Not even the beta testers)