question

Vipin Gahlaut avatar image
Vipin Gahlaut asked

Alexa User Linking: Sample request for access token and refresh token after code is received?

Hi Experts,

We are following Alexa documentation at https://developer.amazon.com/docs/custom-skills/link-an-alexa-user-with-a-user-in-your-system.html to link our user account with Alexa service.

We are using grant type : code as we need to use Smart Home Skill

We are testing API flow. Till step 5 everything is fine and a code is returned by our Oauth2 server. In step6 it is documented

"The Alexa service validates the returned information, then uses the code to request an access token and refresh token pair from your authorization server (specified in the Access Token URI field in the developer portal). Both of these items are saved for the Alexa user"

Can someone please provide a sample sample request sent by Alexa service to obtain access token and refresh tokens by providing code and a response expected by Alexa in which access token and refresh token need to be provided by server.

We are not sure if the code parameter will be provided in req url or in the body of message. If in the msg body what is the format expected ? json?

A sample request and response to obtain access_token and refresh_token by sending code will be very helpful to proceed with the integration.

I hope Amazon have better documentation with examples such as this

Thanks

alexa skills kitalexa smart homeaccount linkingdocumentation
1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Shan avatar image Shan commented ·

I am having same question? Can you help

0 Likes 0 ·
Anand@Amazon avatar image
Anand@Amazon answered

Hi

In Authorization URL which is provided have the important details like vendor_id , consumer key and secret key which you have generated after registering on that platform (to which you want to link your skill) . Once you logged in with this URL then in return your server will send the access token and refresh-token back to your skill which you can parse in your lambda function and use it.

function (request,response){

var accessToken = request.sessionDetails.accessToken;

if(accessToken === null){

response.linkAccount ().shouldEndSession(true).say("Use your alexa app to link account");

} else {

// Put your logic here

}

}

For more details about linking please refer below link :

https://developer.amazon.com/blogs/post/tx3cx1etrzz2npc/alexa-account-linking-5-steps-to-seamlessly-link-your-alexa-skill-with-login-wit

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Shan avatar image Shan commented ·

I am having same question can you help?

Can someone please provide a sample sample request sent by Alexa service to obtain access token and refresh tokens by providing code and a response expected by Alexa in which access token and refresh token need to be provided by server.

We are not sure if the code parameter will be provided in req url or in the body of message. If in the msg body what is the format expected ? json?

0 Likes 0 ·
KasitaTech avatar image
KasitaTech answered

Sure, here's an example. I had trouble with this as well. The weird thing is that amazon is sending query string style parameters but x-www-form-urlencoded in the post BODY. So you have to read the body but don't expect JSON.

POST /authentication/1/oauth HTTP/1.1 url.Values{} grant_type=authorization_code&code=XXXXXXXXXXXXXXXXXXXXXXXXX&redirect_uri=https%253A%252F%252Fpitangui.amazon.com%252Fapi%252Fskill%252Flink%252FM9BEOG3DM65SQ&client_id=XXXXXXXXXXXXXXXXXXXXXX

Also weird is that they're expecting a 200 response from a POST. Our custom framework was set up to always return a 201 for a POST, which really is what a POST should return, but that will break things. We had to rejigger our framework to return a 200 just for this one use case.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.