【发布时间】:2018-09-03 23:39:22
【问题描述】:
当我打电话给Amazon.CognitoIdentity.AmazonCognitoIdentityClient.GetIdAsync() 时,我得到一个NotAuthorizedException:Token is not from a supported provider of this identity pool
我不明白为什么,令牌是通过使用GoogleSignInApi 进行身份验证获得的,并且 AWS 身份池被配置为与用于在 Android 设备上进行身份验证的相同“Google WebApp 客户端 ID”联合到 Google 身份验证提供程序.
我还尝试使用 2 种不同的方式获取 Google 令牌
- 在
GoogleSignInOptions上使用.RequestIdToken()的结果 - 通过调用
GoogleAuthUtil.GetTokenAPI
两个令牌在检查时是不同的,看起来都是好的令牌,并且在给 AmazonCognitoIdentityClient 时都失败并出现相同的错误。显然,用户在 Android 设备上已通过身份验证,应用程序能够获取电子邮件、显示名称等...
var googleSignInOptions = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
.RequestIdToken("Google WebApp Client ID")
.RequestEmail()
.Build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.EnableAutoManage(
this, // FragmentActivity
this) // OnConnectionFailedListener
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
.Build();
mGoogleApiClient.Connect();
var result = await Auth.GoogleSignInApi.SilentSignIn(mGoogleApiClient);
// Only need one or the other, trying to figure out which
var idToken = result.SignInAccount.IdToken;
var authToken = await GetGoogleAuthTokenAsync(result.SignInAccount.Email);
var shortLivedAWScredentials = new CognitoAWSCredentials("identity-pool-id", AWSConfigs.RegionEndpoint);
var cognitoClient = new AmazonCognitoIdentityClient(shortLivedAWScredentials,AWSConfigs.RegionEndpoint);
var logins = new Dictionary<string, string>();
logins["accounts.google.com"] = idToken; // same failure if I use authToken
var request = new GetIdRequest();
request.IdentityPoolId = "identity-pool-id";
request.Logins = logins;
var result = await cognitoClient.GetIdAsync(request); // THIS THROWS Amazon.CognitoIdentity.Model.NotAuthorizedException
private async Task<string> GetGoogleAuthTokenAsync(string accountEmail)
{
Account googleAccount = new Account(accountEmail, GoogleAuthUtil.GoogleAccountType);
string scopes = "audience:server:client_id:" + "Google WebApp Client ID"
var token = await Task.Run(() => { return GoogleAuthUtil.GetToken(this, googleAccount, scopes); });
return token;
}
注意事项 - 在异常发生后,AWS 控制台显示 Cognito 身份池增长了 1 个未经身份验证的身份,谷歌身份的数量没有变化
【问题讨论】:
标签: android amazon-web-services google-signin amazon-cognito aws-cognito