【问题标题】:Search users Amazon Cognito with ListUsers API or iOS SDK使用 ListUsers API 或 iOS 开发工具包搜索用户 Amazon Cognito
【发布时间】:2017-05-12 21:28:00
【问题描述】:

我正在用 Swift 创建一个 iOS 应用程序,但我找不到使用 API 搜索或获取 Cognito 用户列表的方法。根据亚马逊文档,它说要使用 ListUsers API;但是,它没有提供发出请求的端点,并且很难通过 AWS 验证 REST API 请求,所以无论如何可以通过 iOS SDK 来做到这一点?这些是我想包含在我的请求中的参数。

[
        "AttributesToGet": ["username" ],
        "Filter": "username ^= \"micheal\"",
        "Limit": 10,
        "UserPoolId": "\(AWSCognitoUserPoolId)"
    ]

【问题讨论】:

    标签: ios amazon-web-services aws-sdk amazon-cognito aws-cognito


    【解决方案1】:

    您必须通过 Mobile SDK 进行搜索。

    对于 iOS

     // Make a AWSCognitoListUsers Request
        let getUsersRequest = AWSCognitoIdentityProviderListUsersRequest()
    
        // Add the Parameters
        //getUsersRequest?.attributesToGet = ["username"]
        getUsersRequest?.userPoolId = AWSCognitoUserPoolId
    
        // Make the Request
        AWSCognitoIdentityProvider(forKey: AWSCognitoUserPoolId).listUsers(getUsersRequest!, completionHandler: { (response, error) in
    
    
            // The response variable contains the Cognito Response
    
        })
    

    【讨论】:

    • 您好!我现在也有类似的问题。为了使用 AWSCognitoIdentityProviderListUsersRequest(),您需要什么 pod(然后导入)?这是我的帖子:stackoverflow.com/questions/56416551/…
    【解决方案2】:

    有一个 RESTful API 端点可以执行此操作,因为您可以使用 aws CLI 执行此操作。 Command Line List User Pool

    aws CLI 是检查接口是否可以执行此操作的好方法。

    如何在 IOS SDK 中做到这一点是另一回事。 restful 命令集和 SDK 方法名称之间几乎没有关系(无)。我认为这是您要求 CognitoIdentityProvider 做的事情...我认为它是 listUsers 或类似的东西,我认为您也可以列出池。

    +1 其他答案

    【讨论】:

      【解决方案3】:

      这是从 Cognito 获取用户列表的工作代码。

      //IAM User Key and Secret Key Required
      let IAMUserKey = “****”
      let IAMSecretKey = “****”
      
      //Set Credentials
      let credentialsProvider : AWSStaticCredentialsProvider = AWSStaticCredentialsProvider(accessKey: IAMUserKey, secretKey: IAMSecretKey)
      let serviceConfiguration: AWSServiceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialsProvider)
              
      //Register Identity Provider
      AWSCognitoIdentityProvider.register(with: serviceConfiguration, forKey:UserPoolID)
              
      //Request
      let getUsersRequest = AWSCognitoIdentityProviderListUsersRequest()
      getUsersRequest?.userPoolId = UserPoolID
      //mentioned name of attributes in array - name, given_name, username, email and so on
      getUsersRequest?.attributesToGet = ["name"]
      //Add Value in filter you want to search 
      getUsersRequest?.filter = "name = \”jen\””
      //It will search string in including string
      //getUsersRequest?.filter = "name ^= \"jen\""
         
      AWSCognitoIdentityProvider(forKey: UserPoolID).listUsers(getUsersRequest!,completionHandler: {(response, error) in
        print("response:\(String(describing: response))")
        print("error:\(String(describing: error))")
      })
      

      【讨论】:

        猜你喜欢
        • 2017-03-23
        • 2016-11-21
        • 2022-01-11
        • 2023-04-09
        • 1970-01-01
        • 2016-09-17
        • 1970-01-01
        • 2016-05-23
        • 2016-05-23
        相关资源
        最近更新 更多