如何获取Cognito用户池“子” iOS上的属性 [英] How to get Cognito user pool "sub" attribute on iOS

查看:127
本文介绍了如何获取Cognito用户池“子” iOS上的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用认知用户池授权者(没有 AWS_IAM选项,没有自定义编码的授权者)通过API网关调用Lambda方法,并标识在iOS客户端上登录的用户。

I am using a "Cognito User Pool authorizer" (no "AWS_IAM" option, no custom coded authorizer) to call Lambda methods via API Gateway and identify the user logged in on the iOS client.

在Lambda上,我使用通过 event.requestContext.authorizer.claims.sub 从Cognito用户池授权者获得的用户ID(用于存储

On Lambda, I use the user id I get from the Cognito User Pool authorizer via event.requestContext.authorizer.claims.sub (to store the user id with some DynamoDB items).

我现在需要将其与iOS客户端中已登录用户的ID进行比较。

I now need to compare this with the id of the logged in user in the iOS client.

我找到了 [AWSIdentityManager defaultIdentityManager] .identityId ,但这(显然)返回了他 IdentityID (可以在Cognito->联合身份->身份浏览器的AWS控制台中查找),与我在Cognito->用户中看到的 sub ID 不同池->用户和组

I found [AWSIdentityManager defaultIdentityManager].identityId, but this (obviously) returns he IdentityID (which I can look up in the AWS console in Cognito --> Federated Identities --> Identity Browser), which is different from the "sub" id I see in Cognito --> User Pools --> Users and groups

我可以通过AWS iOS SDK获得订阅吗?

Can I get the "sub" via the AWS iOS SDK?

如果无法获取,我应该使用什么其他id参数在Lambda和客户端上进行检索,以标识当前的客户端用户/发出API请求的用户?

If I cannot get it, what other id parameter should I use that I can retrieve both on Lambda and the client to identify the current client user/the user making the API request?

推荐答案

似乎我必须通过这样的用户详细信息来具体请求属性:

It seems that I have to specifically request the attributes via the user details like this:

AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:AWSCognitoUserPoolsSignInProviderKey];
AWSCognitoIdentityUser *user = [pool currentUser];

NSString *mySub;

[[user getDetails] continueWithBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserGetDetailsResponse *> * _Nonnull task) {
    if(!task.error){
        AWSCognitoIdentityUserGetDetailsResponse *response = task.result;
        NSArray<AWSCognitoIdentityProviderAttributeType*> *userAttributes = response.userAttributes;
        for (AWSCognitoIdentityProviderAttributeType *attr in self.userAttributes) {
            if ([attr.name isEqualToString:@"sub"]) {
                mySub = attr.value;
            }
        }
    } else {
        NSLog(@"Error fetching Cognito User Attributes: %@", task.error.localizedDescription);
    }
}];

这篇关于如何获取Cognito用户池“子” iOS上的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆