简体   繁体   English

AWS Cognito检查并获取用户

[英]AWS Cognito check and get users

I'm building an iOS App that is using Amazon MobileHub. 我正在构建一个使用Amazon MobileHub的iOS应用。 Currently it's associated with Cognito and the sign up and sign in flow works great. 目前,它与Cognito关联,并且注册和登录流程效果很好。

What I'm trying to achieve is for one user to be able to add another user as a friend so to speak. 我要实现的目标是使一个用户能够将另一个用户添加为朋友 To make that possible, I need to check if a user with a specific username exists and if it does, get some attributes such as the name of that target user. 为了实现这一点,我需要检查是否存在具有特定用户名的用户,如果存在,请获取一些属性,例如该目标用户的名称。

I've tried to use the get user > get details function but it gives me an error Authentication delegate not set . 我试过使用get user> get details函数,但是它给我一个错误身份验证委托未设置

Here's the code I used: 这是我使用的代码:

var pool: AWSCognitoIdentityUserPool?
let user = pool?.getUser(usernameField.text!)

self.pool = AWSCognitoIdentityUserPool.init(forKey: AWSCognitoUserPoolsSignInProviderKey)

user?.getDetails().continueWith { (task: AWSTask<AWSCognitoIdentityUserGetDetailsResponse>) -> Any? in
  if let error = task.error as NSError? {
    print("ERROR: " + error.localizedDescription)
    return ""
  }

  print(task.result)
  return ""
}

An approach I thought of was to store the username and the attributes I want to access to DynamoDB and then access it there but that will just create double unnecessary entries. 我想到的一种方法是存储要访问DynamoDB的用户名和属性,然后在其中访问它,但这只会创建两个不必要的条目。

The issue you'll run into is that user attributes aren't publicly visible. 您会遇到的问题是用户属性不是公开可见的。 Only the user who has signed in can call GetUser. 只有登录的用户才能调用GetUser。 If it's a back end process, you could do this via the AdminGetUser operation, but this looks client side so I wouldn't recommend that. 如果是后端过程,则可以通过AdminGetUser操作执行此操作,但这看起来是客户端,所以我不建议这样做。 The only real way around this would be to do what you suggested at the bottom of your post, ultimately. 解决此问题的唯一真正方法是最终完成您在帖子底部提出的建议。

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

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