[Tutorial] How to set up Account Linking for Alexa with Auth0 and Jovo


#1

In this guide, we will show you how to set up Account Linking for your Amazon Alexa Skill, without having to deal with all the security issues and the burden of running your own OAuth 2.0 server. We will do this by using Auth0, a service for developers to authorize and authenticate users, which is a helpful tool for Alexa Account Linking.


This is a companion discussion topic for the original entry at https://www.jovo.tech/tutorials/alexa-account-linking-auth0

Alexa Account Linking with Auth0 not getting JWT
#2

Important: Set the default audience in your tenant settings (top right) to https://YOUR-DOMAIN.eu.auth0.com/api/v2/. Else Alexa will only get a really short opaque access token instead of a signed JWT.


#3

Hi all,

I am not receiving a response for retrieving user data after linking account. Here is some data:

  • We have successfully linked account with account linking card
  • We use database connection rather than social connection
  • Alexa does not respond or throw any errors. She simply closes the application.

Here is our current code:

launch : async function (that) {
        if (!that.$request.getAccessToken()) {
            that.$alexaSkill.showAccountLinkingCard();
            that.$speech.addText('Please link you Account');
            that.toIntent("WelcomeIntent");
        } else {
            let token = that.$request.getAccessToken();
            let options = {
                method: 'GET',
                uri: 'https://voicefirsttech.auth0.com/userinfo', // You can find your URL on Client --> Settings --> 
                // Advanced Settings --> Endpoints --> OAuth User Info URL
                headers: {
                    authorization: 'Bearer ' + token,
                }
            };
        
            that.$alexaSkill.progressiveResponse('Processing')
                .then(() => that.$alexaSkill.progressiveResponse('Still processing'));
            await rp(options).then((body) => {
                let data = JSON.parse(body);
                /*
                To see how the user data was stored,
                go to Auth -> Users -> Click on the user you authenticated earlier -> Raw JSON
                */
                return that.tell("HELLO WORLD");// Output: Kaan Kilic, [email protected]
            });
            
        }
    },

And the Response from Alexa

{
	"version": "1.0",
	"session": {
		"new": true,
		"sessionId": "amzn1.echo-api.session.33a28b08-055e-4a74-93a1-0288b6a4b540",
		"application": {
			"applicationId": "amzn1.ask.skill.d3cb6156-f160-401c-ab25-fa04fc5c3861"
		},
		"user": {
			"userId": "amzn1.ask.account.AGV6QLLHMT7HQ5LQI4ZV5AXKCRRFCCPQ6ZC7OTGSEJXAN6E5R6KZQ4NLTE4WD4HCLPIPTTQL7RUSOP5B44U3EZQIGU4NLEOCEITS5O3PR444SJEUSJ3THX7IWPGVQENNVUHIAVV5L2DSL7AKUOXOUEGIM6MGKU4LMJPS3TZUAD4T2642ZZPNPEMREPUT44BB6O6SGK52L6OBVIQ",
			"accessToken": "PrLPPpuqmT3jKaxfPbFBIf58PY-dFJW4"
		}
	},
	"context": {
		"System": {
			"application": {
				"applicationId": "amzn1.ask.skill.d3cb6156-f160-401c-ab25-fa04fc5c3861"
			},
			"user": {
				"userId": "amzn1.ask.account.AGV6QLLHMT7HQ5LQI4ZV5AXKCRRFCCPQ6ZC7OTGSEJXAN6E5R6KZQ4NLTE4WD4HCLPIPTTQL7RUSOP5B44U3EZQIGU4NLEOCEITS5O3PR444SJEUSJ3THX7IWPGVQENNVUHIAVV5L2DSL7AKUOXOUEGIM6MGKU4LMJPS3TZUAD4T2642ZZPNPEMREPUT44BB6O6SGK52L6OBVIQ",
				"accessToken": "PrLPPpuqmT3jKaxfPbFBIf58PY-dFJW4"
			},
			"device": {
				"deviceId": "amzn1.ask.device.AFMRQZLSYMASEMUCNX6HOVIAEWTYEP5XGCGVIHSH4WH5AI4ZJ4UFC7WVS6B23IHKBSYD77WOPFIF6V6OWGNHQ72AWL2IW2R6O5HPK44AP5OFZPQMPFLX3WTSSA72FLGPWHLSSFSQRQ7RXHSK6OLRENQ5OLBA",
				"supportedInterfaces": {
					"Geolocation": {}
				}
			},
			"apiEndpoint": "https://api.amazonalexa.com",
			"apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJhdWQiOiJodHRwczovL2FwaS5hbWF6b25hbGV4YS5jb20iLCJpc3MiOiJBbGV4YVNraWxsS2l0Iiwic3ViIjoiYW16bjEuYXNrLnNraWxsLmQzY2I2MTU2LWYxNjAtNDAxYy1hYjI1LWZhMDRmYzVjMzg2MSIsImV4cCI6MTU1ODEzMjA4MiwiaWF0IjoxNTU4MTMxNz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
		"timestamp": "2019-05-17T22:23:02Z",
		"locale": "en-US",
		"shouldLinkResultBeReturned": false
	}
}
{
	"version": "1.0",
	"response": {
		"shouldEndSession": true
	},
	"sessionAttributes": {}
}

As you can see there are no speech tags in the response.


#4

Does it go into the else block? Could you verify that by logging the data after making the request?

Also, I would probably get rid of the progressive responses part for now until it’s working to remove another layer of complexity


#5

Jan,

here is the response I receive:

{ 
  sub: 'auth0|8683a81e-4975-40d9-b9ce-cc0a3edbc743',
  nickname: 'voicefirsttech',
  name: '[email protected]',
  picture: 'https://s.gravatar.com/avatar/c18b64d675c7a176072bcf363459ac21?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fvo.png',
  updated_at: '2019-05-27T14:40:16.474Z',
  email: '[email protected]' }
{

However,
I would like the FULL user profile:


#6

Hi, added something in the other thread: Get FULL Profile in Alexa Account Linking


#7

Can we use the JOVO CLI to add account linking?

Looks like account linking is not same as SMAPI for Alexa

Does Jovo offer these capabilities?

https://developer.amazon.com/docs/smapi/account-linking-schemas.html


#8

Hi @jan Jan,
I have followed the same steps, i have authenticated using google in the login window. My endpoint throws jws malformed, also the token got shorted not the one given in auth0 quick start.


#9

@jan Is there any way to make a single Jovo app handle account linking for both Google Assistant and Alexa?


#11

Hi @jan,
I’m trying to setup the Account Linking with Google.

I have a simple code:
LAUNCH() {
if (this.$request.getAccessToken()) {
this.tell(“success”);
} else {
this.alexaSkill()
.showAccountLinkingCard()
.tell(“Go the Alexa app and set account linking”);
}
}

However, when i do jovo run to open the debugger, if use my Echo device and tell “Alexa, open [app name]” I correctly retrieve the accessToken and the request user id corresponds to my amazon user id . When I click the “LAUNCH” button from the debugger console the user id that sends the request is “userId”: “jovo-debugger-user” and the access token is not received.
How can I retrieve it if I use the console to debug and not the alexa device?
Thank you!


#12

Hi @jan,
Can we do account linking without Auth0, I have to used idp instend of auth0 is it possible to do account linking with idp ?

Please help me.
Thanks.


#13

Yes, any account linking service that is based on oAuth 2 should work


#15

Hey Guys currently my application is working in English but if test in Spanish the app not is working.

            if (
		!this.$request?.getAccessToken() &&
		!this.$alexaSkill?.$dialog?.alexaRequest?.context?.System?.person
			?.accessToken
	) {
		return this.$alexaSkill
			?.showAccountLinkingCard()
			.tell(this.t("error-linked-account"));
	} else {
		return this.followUpState(ROUTE_NAMES.MAIN).ask(this.t("main-select"));
	}

#16

@Anne_Koep-Lehmann I’m running into this issue but I cannot figure out where to set the audience. The Alexa dev console Account Linking page does not have a field for audience or tenant. Where should I be setting this?

Update: I found the solution here
https://community.auth0.com/t/access-token-is-not-jwt-format/61945/8