如何自动将用户划分为不同的组(身份池)



我正在我的iOS应用程序中使用AWS Cognito来实现用户注册和登录功能。我使用了官方的Amplify SDK DOC(https://aws-amplify.github.io/docs/ios/authentication(作为参考,该应用程序运行良好。但是,实际上我想给我的用户不同的访问权限,可以实现不同的内容(如 S3 中的文件(。

当用户注册应用时,他们必须选择一个组。根据组的不同,他们被赋予不同的访问权限。

我已经阅读了 SDK DOC 和开发人员指南,但我还没有找到实现此功能的好方法。

是否有任何可用于将用户划分到不同身份池中的认知功能?或者任何人都可以向我展示一些允许用户具有不同访问权限的示例。

AWSMobileClient.sharedInstance().signUp(username: "your_username",
                                        password: "Abc@123!",
                                        userAttributes: ["email":"john@doe.com", "phone_number": "+1973123456"]) { (signUpResult, error) in
    if let signUpResult = signUpResult {
        switch(signUpResult.signUpConfirmationState) {
        case .confirmed:
            print("User is signed up and confirmed.")
        case .unconfirmed:
            print("User is not confirmed and needs verification via (signUpResult.codeDeliveryDetails!.deliveryMedium) sent at (signUpResult.codeDeliveryDetails!.destination!)")
        case .unknown:
            print("Unexpected case")
        }
    } else if let error = error {
        if let error = error as? AWSMobileClientError {
            switch(error) {
            case .usernameExists(let message):
                print(message)
            default:
                break
            }
        }
        print("(error.localizedDescription)")
    }
}

您不必将用户放入不同的身份池中。Cognito 已有可用于分配不同角色的用户组。我不熟悉IOS,但应该有一个管理员可以使用的用户添加到组的方法。

最新更新