2

I would like to use the Amazon Alexa voice service to create a voice interface for Salesforce. But I've run into problems.

I am reading here:

http://blog.enree.co/2015/12/salesforce-amazon-echo-integrate-alexa.html

and I read:

"unfortunately when linking accounts Amazon's Alexa Skills page doesn't sends to the login page the redirect_uri parameter that is mandatory for successfull Salesforce OAuth process completion."

There might be a variable name conflict, since both SalesForce and Amazon use "redirect_uri" in the URLs they use as part of their Oauth process.

On the Amazon side, I believe I've done all I can to set this up.

I've gone to my Developer Portal:

https://developer.amazon.com/edw/home.html#/skill/amzn1.echo-sdk-ams.app.b9ae614ad/info

(Obfuscated for security)

Under "Account Linking or Creation", under "Domain List", I whitelisted this domain:

salesforce.com

If I take my iPhone and open the Alexa app, I can search for my skill, find it, and then I click "Enable".

Under "Authorization URL" I put:

https://alexa.salesvoiceapp.com/auth

(You might ask, why don't I go point straight to Salesforce? Well, I was hoping to harvest the Amazon user_id, so I went to my own server first. This was a failed idea.)

I've set this to "Implicit Grant".

When the user arrives on my server I harvest the Amazon user_id and then redirect to Salesforce:

https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=URAx31ViKQovfPPXrCvi9CAfzsJJ8AtoACYEWqeB_IMxBQ&redirect_uri=https%3A%2F%2Falexa.salesvoiceapp.com%2Fauth-callback&state=

And then in the Alexa app I see:

Not Found The requested URL /&redirect_uri=https://alexa.salesvoiceapp.com/auth-callback was not found on this server

I believe that Amazon is causing this error? Or is this a SalesForce error?

Do I have to specify a "redirect_uri" as part of the URL? When I created my Connected App I specified this as the callback URL:

https://alexa.salesvoiceapp.com/auth-callback

Can I get SalesForce login to use that URL automatically, without me having to send it along as a parameter in the URL that I use to redirect users to SalesForce?

1

OK, completely updating this with code. Basically you need to add a header and transform the request, and the munge instance_url to the access token and add an expiry to the response. Note this uses their Auth Code flow.

Here's the endpoint I use for the token URI, using Node + Express:

app.post('/token',function (req, res) {


console.log(req.body);
  var sr = sync_request('POST', 'https://login.salesforce.com/services/oauth2/token',
                      {
                      headers: {'Content-Type':'application/x-www-form-urlencoded','Accept':'application/json'},
                      body: 'grant_type='+req.body.grant_type+'&code='+req.body.code+'&refresh_token='+req.body.refresh_token+'&client_id='+req.body.client_id+'&client_secret='+req.body.client_secret+'&redirect_uri='+req.body.redirect_uri
                      });
  console.log(sr.getBody('utf8'));
  response = JSON.parse(sr.getBody('utf8'));

  response.access_token = response.access_token + " " + response.instance_url;
  response.expires_in = 5400; //in seconds, set this to be less than your setting under session management.

  res.jsonp(response);
});

Then you can grab the token and instance url by splitting on the space.

I've done a write up on using it, including the Amazon setup side.

0

In my case, I was trying to do it with the UI that amazon provides under the skills(Account Linking). Everything was perfectly set up and I was not able link my skill to SF via the connected app. I noticed that I had to provide scopes as api and refresh_token. It worked fine after that and I was able to link my SF account to my alexa skill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.