我正在密切关注此文档以从我的 iOS 应用程序中授权硬件:
在 iOS 部分,在第 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];
}
productId
scopeData应该是什么?正如我已经阅读了其他一些帖子,据说它productId
取自在AVS Developer Portal中创建的应用程序的 ID 列,它与iOS 入门指南中的App Console中提到的文档没有链接。所以我对如何/在哪里采取.productId
deviceSerialNumber
可以是任何唯一的字符串吗?
我在“将授权代码从移动应用程序传输到支持 Alexa 的产品”部分中描述的项目 1) 和 2) 中在 ObjC 中实现了代码挑战方法。这是对的吗?(因为我没有参考示例)
- (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<base64Enc.length; i++) { // remove "="; replace "+" with "-"; replace "/" with "_" as referenced from: http://tools.ietf.org/html/draft-ietf-oauth-spop-10#appendix-A
unichar c = [base64Enc characterAtIndex:i];
if (c == '=') {
continue;
}
else if (c == '+') {
[ret appendString:@"-"];
}
else if (c == '/') {
[ret appendString:@"_"];
}
else {
[ret appendFormat:@"%C", c];
}
}
return ret;
}
问候,