简体   繁体   English

如何使用Cognito Identity对我的身份/用户池进行身份验证?

[英]How can i authenticate to my Identity/User Pool with Cognito Identity?

I have been trying to solve this for a few days now but i can't figure out what the problem is. 我一直试图解决这个问题几天,但我无法弄清问题是什么。

I have a user pool and an identity pool on AWS Cognito. 我在AWS Cognito上有一个用户池和一个标识池。 I have run the sample code and used it to log in and register users with Facebook and Google+ successfully. 我已经运行了示例代码并使用它来成功登录并注册用户和Facebook和Google+。 After login i am able to authenticate using the token to use SNS or the Sync services. 登录后,我可以使用令牌进行身份验证以使用SNS或同步服务。

I have registered a user and got a token (after logging in) with Cognito Identity. 我已经注册了一个用户,并在使用Cognito Identity获得了一个令牌(登录后)。 However the next step is to use the token to authenticate into the identity pool. 但是,下一步是使用令牌进行身份验证。 This is where i keep getting the error 这是我不断收到错误的地方

I have followed the instructions from Integrating User Pools with Amazon Cognito Identity and I get a token which I then try to pass it along with the pool id to the credentials provider. 我遵循了将用户池与Amazon Cognito Identity集成的说明,然后我获得了一个令牌,然后我尝试将其与池ID一起传递给凭证提供程序。

  credentialsProvider.clear();
  credentialsProvider.withLogins(loginMap).refresh();

My code fails on refresh(). 我的代码在refresh()上失败了。 At this point credentialsProvider is a AWSBasicCognitoIdentityProvider and refresh() fails in the super.refresh() which calls getIdentityId() in the abstract parent class AWSAbstractCognitoIdentityProvider 此时,credentialsProvider是一个AWSBasicCognitoIdentityProvider,而refresh()在super.refresh()中失败,它在抽象父类AWSAbstractCognitoIdentityProvider中调用getIdentityId()

@Override
public String getIdentityId() {
    if (identityId == null) {
        GetIdRequest getIdRequest = new GetIdRequest()
                .withAccountId(getAccountId())
                .withIdentityPoolId(getIdentityPoolId())
                .withLogins(loginsMap);

        appendUserAgent(getIdRequest, getUserAgent());

        GetIdResult getIdResult = cib.getId(getIdRequest);

No matter what values i put in the loginsMap, i get the error 无论我在loginsMap中放置什么值,我都会收到错误

Invalid login token. 登录令牌无效。 Issuer doesn't match providerName Issuer与providerName不匹配

at cid.getid(getIdRequest). 在cid.getid(getIdRequest)。

Most of the code is available to download free if you create an app in the Mobile Hub and generate the code. 如果您在Mobile Hub中创建应用程序并生成代码,则大多数代码都可以免费下载。 You can then configure authentication providers - FB, Google , etc. 然后,您可以配置身份验证提供程序 - FB,Google等。

What am I doing wrong ? 我究竟做错了什么 ?

Thanks. 谢谢。

Edit : Here are examples of what i have tried The token is always the object in the map. 编辑 :以下是我尝试过的示例。令牌始终是地图中的对象。 Below are the different keys 以下是不同的按键

  • "cognito-identity.amazonaws.com" “cognito-identity.amazonaws.com”
  • the User Pool id - us-east-1_xxxxxxxxx 用户池ID - us-east-1_xxxxxxxxx
  • the User Pool ARN - cognito-idp:us-east-1:xxxxxxxxxxxx:userpool/us-east-1_xxxxxxxxx 用户池ARN - cognito-idp:us-east-1:xxxxxxxxxxxx:userpool / us-east-1_xxxxxxxxx

OK i found the answer - I was putting in the wrong key value in the loginMap. 好的,我找到了答案 - 我在loginMap中输入了错误的键值。

it should be 它应该是

cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>

as it says in the documentation linked in the question 正如它在问题中链接的文档中所述

I don't know how I didn't see that. 我不知道我怎么没看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在android中使用Cognito Identity集成用户池 - Integerate User pool with Cognito Identity in android 如何在 Amplify for Android 中将 Cognito 身份池与 UnAuthenticatd 用户一起使用 - How to use Cognito identity pool with UnAuthenticatd users in Amplify for Android AWS Cognito身份池:如何检查电子邮件属性是否已验证 - AWS Cognito Identity Pool: How to check if email attribute is verified or not AWS Cognito身份池登录和持久性 - AWS Cognito Identity Pool Login and Persistence Amazon Cognito身份池区域不存在 - Amazon Cognito Identity Pool Region not exist 如何在 Android 中将 TransferUtility 与 Cognito 用户/身份池一起使用 - How to use TransferUtility with Cognito user / Identity pools in Android 如何搜索Amazon Cognito身份? - How to search Amazon Cognito Identity? 使用 Amazon Cognito 未经身份验证的身份池 ID 是否允许在 Android 应用程序之外访问我的 dynamodb? - Will using an Amazon Cognito unauthenticated identity pool ID allow access to my dynamodb outside of Android app? 如何使用社交身份提供程序在用户池中创建用户? - How to create user in user pool using social identity provider? 如何在用户通过身份验证之前编辑“AWS cognito”用户池中用户的电话号码? - How can I edit a phone number of a user in user pool of `AWS cognito` before the user is authenticated?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM