question

eric-cantona avatar image
eric-cantona asked

automation of authentication

Is it possible to authenticate a session without having to manually enter data into the "login to amazon" page, and cutting/pasting codes etc. I'd like to use the demo code without having manual steps in the authentication step. Is that possible?
alexa voice service
10 |5000

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

Bobby@Amazon avatar image
Bobby@Amazon answered
Hi, Yes it is possible to programmatically handle authentication with AVS. Login with Amazon supports two separate methods of token generation: 1) Implicit Grant -- requires manual interaction each time you get a new token 2) Authorization Code Grant -- allows you to generate a refresh token which can then be used to programmatically retrieve your authentication token as necessary. The included examples zip with AVS has a sample server/application that demonstrate this programmatic authentication support. You can find the guide to using it here: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/reference-implementation-guide
10 |5000

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

eric-cantona avatar image
eric-cantona answered
Thanks Bobby. I'm using the reference implementation. The implementation notes state the following steps: 1. Product registration website collects identifying information. 2. Product registration website creates a registration code and passes it back to the user. 3. Ask the user to paste the authorization URL into a browser. 4. The user enters their Amazon.com credentials in the Login with Amazon website and authorizes the product to access the Alexa Voice Service on their behalf. 5. Securely transfer the access and refresh tokens from the product manufacturer's website to the user's specific instance of the product. So step 3 is the problem. I understand that once this process has been completed once, it's possible to refresh the token at step 5 so steps 1-4 don't need to be repeated. Is there a way to always eliminate/automate step 3? Also, if the server is stopped and restarted, it seems like you have to repeat 1-5 even if the access taken hasn't expired? Am I misunderstanding something? As a next step, can you provide an example of how I could achieve the speechrecognizer request using curl? I'm not too familar with java and would like to eventually get this all running in python. Thanks
10 |5000

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

Beefalo avatar image
Beefalo answered
[DELETED]
10 |5000

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

Bobby@Amazon avatar image
Bobby@Amazon answered
Hey Eric, Unfortunately, given the OAuth protocol, the manual steps 3/4 are necessary at least once. Note that you can enter the URL into any browser on any device(obviously you wouldn't be able to copy/paste it in that case but hopefully it is not too long). Yes, the provided server keeps everything in memory so upon restarting it everything needs to be re-done. It was meant to be a simple example of how to use the APIs/Services. It can be used as a resource for building a proper solution that stores this information in a secure database such that it can be retained between launches. Creating a CURL command may be difficult given the request is in multipart format and has binary audio data in it as well. We will look into this and get back to you soon. Thanks, Bobby
10 |5000

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

Bobby@Amazon avatar image
Bobby@Amazon answered
Hey Eric, Although not a curl request, here is a very basic Python script that shows you how to make a speechrecognizer request. Please note this is just something I hacked up as an example and should only be used as an idea for implementing your own python implementation. Obviously you need to fill in your authentication token and audio data, but just to confirm it is working you can use a random string for audio data and will get back a 204: import urllib import urllib2 url = ' https://access-alexa-na.amazon.com/v1/avs/speechrecognizer/recognize' headers = { 'Authorization' : 'Bearer ', 'Content-Type':'multipart/form-data; boundary=BLAH1234' } data = '\r\n--BLAH1234\r\nContent-Disposition: form-data; name="metadata"\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n{"messageHeader":{}, "messageBody":{"profile":"alexa-close-talk", "locale":"en-us", "format":"audio/L16; rate=16000; channels=1"}}\r\n--BLAH1234\r\nContent-Disposition: form-data; name="audio"\r\nContent-Type: audio/L16; rate=16000; channels=1\r\n\r\n \r\n--BLAH1234--\r\n' req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) print response.getcode() -Bobby
10 |5000

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

eric-cantona avatar image
eric-cantona answered
Hi Bobby, Thanks for that. Your code snippet was perfect. I've got a python script now that does all of the steps. I've even used selenium to automate entering in my credentials on the amazon login page. All good. I appreciate your help. Eric.
10 |5000

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

tom forti avatar image
tom forti answered
Eric, I am attempting to do the same thing you did. Would you be able to share your PY code on how you did it? Tom
10 |5000

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