gpt4 book ai didi

ios - 按角色过滤 AWS-Cognito 用户

转载 作者:行者123 更新时间:2023-11-28 15:44:53 27 4
gpt4 key购买 nike

我整天都在寻找如何做到这一点,现在可以使用了。

假设我的用户池中有两个用户,John Admin 和 Jim User。我有一个 View Controller ,我希望 John Admin 而不是 Jim User 可以访问它。问题是我不知道如何在我的应用程序中区分 John 和 Jim。

有没有办法知道 John Admin 在我的管理员组/角色中但 Jim 不在?

编辑:询问用户属性给了我:

{"UserAttributes": [
{ "Name": "sub", "Value": "NUMBERS"},
{ "Name": "email_verified", "Value": "true"},
{ "Name": "phone_number_verified", "Value": "false"},
{ "Name": "phone_number", "Value": "NUMBERS"},
{ "Name": "email", "Value": "EMAIL"}],
"Username": "johnadmin"}

最佳答案

我使用属性解决了它,因为 IdentityID 没有像我想的那样显示嵌入的组。

var pool: AWSCognitoIdentityUserPool?
var user: AWSCognitoIdentityUser?

在我感兴趣的方法中:

if let strongUser = self.user {
strongUser.getDetails().continueOnSuccessWith { (task) -> AnyObject? in
DispatchQueue.main.async(execute: {
if let response:AWSCognitoIdentityUserGetDetailsResponse = task.result {
for attr in response.userAttributes! {
if attr.name == "custom:privilege", attr.value == "admin" {
self.adminButton.isHidden = false
return
}
}
}
self.adminButton.isHidden = true
})
return nil
}
} else {
adminButton.isHidden = true
}

缺点是在未登录时,应用程序无法写入自定义属性,因此我使用 AWS-CLI 来提升用户:

aws cognito-idp admin-update-user-attributes --user-pool-id <POOLID> --username <USERNAME> --user-attributes '{"Name":"custom:privilege","Value":"admin"}'

关于ios - 按角色过滤 AWS-Cognito 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43269063/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com