gpt4 book ai didi

django - 如何使用 Keycloak Token 获取权限列表

转载 作者:行者123 更新时间:2023-12-05 07:27:02 27 4
gpt4 key购买 nike

无法使用 Keycloak token 获取用户权限列表。出现类似 keycloak.exceptions.KeycloakAuthorizationConfigError: Keycloak settings not found 的错误。加载授权 key 斗篷设置。

我正在使用 python-keycloak

key 斗篷配置

keycloak_openid = KeycloakOpenID(server_url=config.server_url,
client_id=config.client_id,
realm_name=config.realm_name,
client_secret_key=config.client_secret_key,
verify=True)


keycloak_openid.load_authorization_config(os.path.join(local_path, 'Dynamic_Client-authz-config.json'))

userinfo = keycloak_openid.get_permissions(token, method_token_info='introspect')
print(userinfo)

key 斗篷设置文件

{
"allowRemoteResourceManagement": false,
"policyEnforcementMode": "PERMISSIVE",
"resources": [
{
"name": "Default Resource",
"type": "urn:Dynamic_Client:resources:default",
"ownerManagedAccess": false,
"attributes": {},
"_id": "2c2a046f-84b2-42a8-a028-c6ae56ad63a1",
"uris": [
"/*"
]
}
],
"policies": [
{
"id": "f570c7e7-8168-4fb8-b05c-4df8be9398d0",
"name": "Default Policy",
"description": "A policy that grants access only for users within this realm",
"type": "js",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"code": "// by default, grants any permission associated with this policy\n$evaluation.grant();\n"
}
},
{
"id": "836d2453-ad1c-4482-b726-49875a8ba64f",
"name": "Default Permission",
"description": "A permission that applies to the default resource type",
"type": "resource",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"config": {
"defaultResourceType": "urn:Dynamic_Client:resources:default",
"applyPolicies": "[\"Default Policy\"]"
}
}
],
"scopes": []
}

请找到我的问题的解决方案

最佳答案

所以我假设您正在寻找职位?

如果是这样,请使用内省(introspection) token ,这对我有用

内省(introspection) token

    token_info = keycloak_openid.introspect(token['access_token'])
print(token_info['resource_access']['client-name']['roles'])

关于django - 如何使用 Keycloak Token 获取权限列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54074978/

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