gpt4 book ai didi

security - 使用 JWT 受众字段进行授权角色

转载 作者:行者123 更新时间:2023-12-03 06:40:43 25 4
gpt4 key购买 nike

我正在考虑使用 JWT 受众字段在我的应用中实现基于角色的授权。

因此,我的 ServiceA 需要“RoleA”受众存在,ServiceB 需要“RoleB”等。然后,当我发出 JWT 时,我会包含适当的受众。

JWT 草案的相关部分 spec :

The aud (audience) claim identifies the recipients that the JWT is intended for. Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the aud claim when this claim is present, then the JWT MUST be rejected... The interpretation of audience values is generally application specific.

看来这可行,但由于我是 JWT 的新手,我想知道:基于角色的授权是否适合受众领域的用例?或者我应该使用带有自定义角色数组等的有效负载来滚动自己的逻辑?

谢谢

最佳答案

我了解受众,而不是可以授权用户的消费者/应用程序列表。

在我的应用程序中,我将角色放入有效负载中自己的数组中。例如这样。

{
"sub": 1234567890,
"exp": 9876543210,

"name": "John Doe",
"roles": ["USER", "EDITOR"]
}

在服务器上,我被授权使用 spring security 和从“sub”加载的用户。

在客户端上,我可以使用这些角色来显示正确的按钮和字段。

关于security - 使用 JWT 受众字段进行授权角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26837895/

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