cha*_*ith 2 amazon-web-services ios amazon-cognito google-signin
我正在尝试使用Google登录SDK在Google应用程序中将Google与Amazon Cognito集成,但我似乎无法弄清楚如何正确获取JWT ID令牌.我相信,所有内容都设置正确,因为Google Sign-In和Cognito都是独立工作的.
我正在设置这样的GIDSignIn.
[GIDSignIn sharedInstance].scopes = @[kGTLAuthScopePlusLogin, kGTLAuthScopeDrive];
[[GIDSignIn sharedInstance] setClientID:kClientID];
[GIDSignIn sharedInstance] setServerClientID:kServerClientId];
Run Code Online (Sandbox Code Playgroud)
然后拿到id_token,按规定这里唯一的例外是,我使用谷歌的登录和而非Google+登入,它没有GTMOAuth2Authentication.
- (void)googleSignedIn:(GIDGoogleUser *) user
{
NSLog(@"AWSManager: Google signed in, id token = %@", user.authentication.idToken);
NSString *idToken = user.authentication.idToken;
self.credentialsProvider.logins = @{ @(AWSCognitoLoginProviderKeyGoogle): idToken};
Run Code Online (Sandbox Code Playgroud)
但是idtoken不是json格式的web令牌,它只是一大块字符.AWS抛出此错误 -
AWSiOSSDKv2 [Error] AWSIdentityProvider.m line:185
| __51-[AWSAbstractCognitoIdentityProvider getIdentityId]_block_invoke169
| GetId failed.
Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=9
"The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 9.)"
UserInfo=0x8fa5eb8e4e40{__type=NotAuthorizedException, message=Token is not from a supported provider of this identity pool.}]
Run Code Online (Sandbox Code Playgroud)
我不知道我该怎么做.我对objective-c很新,并且之前在Android上完成了所有这些工作.在android上我做了:
String mServerClientId = "audience:server:client_id:xxxxxxxxxx.apps.googleusercontent.com"
String token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, mServerClientId);
Run Code Online (Sandbox Code Playgroud)
检索令牌,但据我所知,在iOS上没有这样的东西.如果需要,我可以提供更多信息.
谢谢!
从错误看,在标识池配置中未正确设置clientId.Google为每个平台提供不同的客户端ID,为了支持多个客户端ID,您应该使用Cognito对通用OpenID Connect身份提供商的支持.请按以下步骤操作:
您可以按照谷歌登录时Cognito文件在这里和OpenID提供商连接这里.
此外,您获得的令牌实际上是Base64编码.它有三个部分用句点分隔.
您可以使用这个很酷的工具来解码令牌.
谢谢,
Rachit