简体   繁体   English

将AWS Cognito Pool用户转换为联合用户ID

[英]Converting AWS Cognito Pool user to Federated user Id

I need to get the Federated Identity Id for a Cognito Identity Pool user. 我需要为Cognito身份池用户获取联合身份ID。

My dynamodb tables use userId as the primary key, where userId is the Cognito Federated Identity Id (configured using mobilehub). 我的dynamodb表使用userId作为主键,其中userId是Cognito联合身份ID(使用mobilehub配置)。 In an android app, I make a query using an AmazonCognitoIdentityProviderClient (which is properly instantiated with the IdentityManager and uses CognitoUserPoolsSignInProvider & FacebookSignInProvider) -- this query successfully retrieves all of the users in my cognito user pool (I do use a filter, but have removed it for simplicity, here): 在一个android应用中,我使用AmazonCognitoIdentityProviderClient(使用IdentityManager正确实例化并使用CognitoUserPoolsSignInProvider和FacebookSignInProvider)进行查询-该查询成功检索了我的cognito用户池中的所有用户(我确实使用了过滤器,但具有为简单起见,已将其删除):

ArrayList<UserType> cognitoPoolUsers = instantiatedAmazonCognitoIdentityProviderClient().listUsers().getUsers();

The users in cognitoPoolUsers have attributes like email and username, but the userId that is used for the dynamo primary key is the userId of the federated user that is linked to the cognitoPoolUser. cognitoPoolUsers中的用户具有电子邮件和用户名之类的属性,但是用于发电机主键的userId是链接到cognitoPoolUser的联盟用户的userId。

How can I retrieve the corresponding federated identity userId, given that I have successfully retrieved the list of cognitoPoolUsers? 鉴于我已经成功检索了cognitoPoolUsers列表,如何检索对应的联合身份userId?

End goal (I would actually use batchLoad, but for simplicity..): 最终目标(为了简单起见,我实际上会使用batchLoad。):

ArrayList<UserType> cognitoPoolUsers = instantiatedAmazonCognitoIdentityProviderClient().listUsers().getUsers();

for(int k=0; k<cognitoPoolUsers.size(); k++) {
  UserType cognitoPoolUser = cognitoPoolUsers.get(k);
  SomeDynamoDO dynamoDO = new SomeAmazonDO();

  //Unknown Step:
  String correspondingFederatedId = extractFederatedId(cognitoPoolUser);

  dynamoDO.setUserId(correspondingFederatedId)
  dynamodbMapper.load(dynamoDO)
} 

You can get the Identity Id for a Userpool user by logging in the user to get an Id token and calling the GetId API. 您可以通过登录用户以获取ID令牌并调用GetId API来获取Userpool用户的身份ID。 Using Android SDK: 使用Android SDK:

//Login and get the Id token. 
//The 'iss' claim of the token without https: will be the providerName
credentialsProvider = new CognitoCachingCredentialsProvider(context, IDENTITY_POOL_ID,REGION);
Map<String, String> logins = credentialsProvider.getLogins();
if (logins == null) {
    logins = new HashMap<String, String>();
}
logins.put(providerName, token);
credentialsProvider.setLogins(logins);
String id=credentialsProvider.getIdentityId();

If you want to use low-level API calls, this is the relevant call. 如果要使用低级API调用,则为相关调用。 Add the Userpool token in the login map parameter. 在登录映射参数中添加Userpool令牌。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM