question

Quan Nguyen avatar image
Quan Nguyen asked

productId, code challenge: what should they be?

Hi, I am following closely this document to authorize a hardware from my iOS app: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/authorizing-your-alexa-enabled-product-from-an-android-or-ios-mobile-app In iOS section, at step 5): - (IBAction)onLogInButtonClicked:(id)sender { NSArray *requestScopes = [NSArray arrayWithObjects:@"alexa:all", nil]; NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; NSString* scopeData = [NSString stringWithFormat:@"{\"alexa:all\":{\"productID\":\"%@\"," "\"productInstanceAttributes\":{\"deviceSerialNumber\":\"%@\"}}}", productId, deviceSerialNumber]; options[kAIOptionScopeData] = scopeData; options[kAIOptionReturnAuthCode] = @YES; options[kAIOptionCodeChallenge] = @"CODE_CHALLENGE_GOES_HERE"; options[kAIOptionCodeChallengeMethod] = @"S256"; [AIMobileLib authorizeUserForScopes:requestScopes delegate:delegate options:options]; } what should productId in scopeData be? As I have read some other posts, it is said that productId is taken from ID column of an app created in AVS Developer Portal ( https://developer.amazon.com/edw/home.html#/avs/list), which is not linked with the document as it mentions to App Console ( http://login.amazon.com/manageApps) in Getting Started guide for iOS: http://login.amazon.com/ios#install_login_with_amazon_library. So I am confused at how/where to take the productId. deviceSerialNumber can be any string in my definition. I implemented a code-challenge-method in ObjC based on item 1) and 2) described in "Transferring an Authorization Code from a Mobile App to an Alexa-enabled Product" section. Not sure if it is correct or not since I have no reference example. - (NSString *)codeChallenge { verifier = [NSString randomStringWithLength:128]; // generate 128-char string containing [A-Z], [a-z], [0-9], "-", "_", ".", "~" NSData *sha256 = [[verifier dataUsingEncoding:NSUTF8StringEncoding] SHA256]; // SHA256 that string NSString *base64Enc = [sha256 base64EncodedStringWithOptions:0]; // base64 encode SHA256 result NSLog(@"base64Enc: %@", base64Enc); NSMutableString *ret = [NSMutableString string]; for (NSInteger i=0; i
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.

1 Answer

elstryan@Amazon avatar image
elstryan@Amazon answered
Hi, Thanks for your interest in AVS! I'm happy to help out with this inquiry. #1) productId is taken from ID column of an app created in AVS Developer Portal #2) Yes deviceSerialNumber can be any string Your code challenge looks correct - are you seeing any errors?
10 |5000

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