我致电NotAuthorizedException:Token is not from a supported provider of this identity pool
Amazon.CognitoIdentity.AmazonCognitoIdentityClient.GetIdAsync()
我不明白为什么,令牌是通过使用GoogleSignInApi
进行身份验证获得的,并且AWS身份池配置为使用相同的" Google WebApp客户端ID"来联合到Google身份验证提供商。用于在Android设备上进行身份验证。
此外,我还尝试使用两种不同的方式获取Google令牌
.RequestIdToken()
GoogleSignInOptions
的结果
GoogleAuthUtil.GetToken
API 两个令牌在检查时都是不同的,两者都看起来像是一个好的令牌,并且在给予AmazonCognitoIdentityClient
时都会失败并出现相同的错误。显然,用户在Android设备上进行了身份验证,该应用程序可以获取电子邮件,DisplayName等...
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;
}
答案 0 :(得分:3)
搜索时间,我终于找到了解决方案。基本上,AWS Cognito Identity Pool 与Google+的联盟完全被破坏,但不要绝望。您需要做的是联合到OpenID提供商。
首先,转到AWS控制台&gt; IAM&gt;身份提供者&gt;创建提供商&gt;提供商类型= OpenID Connect&gt;提供商网址= https://accounts.google.com&gt; Audience =&#34;您在Google Developer Console中创建的Android或iOS的Google客户端ID&#34;
请注意,不要使用&#34; Google Web App客户端ID&#34;为了观众。
其次,转到AWS控制台&gt; Cognito&gt;联合身份池。选择您的身份池,然后单击&#34;编辑身份池&#34;,然后导航到OpenID选项卡(不是Google+选项卡,甚至不使用它不起作用的那个)。您现在应该会看到一个标题为&#34; accounts.google.com&#34;的复选框,请检查它。
第三,去编辑您的移动应用源代码,并确保使用&#34; Google WebApp客户端ID&#34;您在构建用于调用GoogleAuthUtil.GetTokenGoogleAuthUtil.GetToken(this, googleAccount, scopes)
的范围字符串时在Google Developer Console中生成的。那是scopes = "audience:server:client_id:" + "webClientId"
现在,您对var result = await cognitoClient.GetIdAsync(request);
的电话会成功。