このドキュメントに厳密に従って、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 はどうあるべきですか? 他の投稿を読んだことがありますが、これはAVS Developer PortalproductId
で作成されたアプリの 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;
}
よろしく、