OAuth / OIDC - 如何通知资源服务器有关用户身份的信息
OAuth / OIDC - How to inform a resource server about a user's identity
我想在我的系统中实施 OAuth / OIDC。我会有一个中央 OpenID 提供程序和多个资源服务器。这些资源服务器中的每一个都需要知道他们正在与哪个用户交谈。为此,他们需要用户的 ID。
我的第一直觉是将 ID 令牌传递给资源服务器,但无论我在哪里看,我都读到这是一个坏主意,而且通常不是这样完成的。
下一个想法是将该数据存储在访问令牌中。 OAuth 标准说,该令牌对客户端是不透明的(但不一定对资源服务器)。这是否意味着将用户 ID 存储在访问令牌中是可行的方法,还是有更好的选择?
是的。可以将用户 ID 存储在访问令牌中,您只需对其进行解码即可获取其值。对于 JWT 访问令牌,它也通过将用户 ID 存储在声明名称 sub
.
的字段中来执行相同操作
对于不透明令牌,有一个 specification defines how to get the user 's info for the resource server . It basically makes a request to the authorization server to validate the access token as well as returning the user 's info. It also mentions to use the field name sub
来引用定义为 :
的用户 ID
Subject of the token, as defined in JWT [RFC7519]. Usually a
machine-readable identifier of the resource owner who authorized this
token.
我想在我的系统中实施 OAuth / OIDC。我会有一个中央 OpenID 提供程序和多个资源服务器。这些资源服务器中的每一个都需要知道他们正在与哪个用户交谈。为此,他们需要用户的 ID。
我的第一直觉是将 ID 令牌传递给资源服务器,但无论我在哪里看,我都读到这是一个坏主意,而且通常不是这样完成的。
下一个想法是将该数据存储在访问令牌中。 OAuth 标准说,该令牌对客户端是不透明的(但不一定对资源服务器)。这是否意味着将用户 ID 存储在访问令牌中是可行的方法,还是有更好的选择?
是的。可以将用户 ID 存储在访问令牌中,您只需对其进行解码即可获取其值。对于 JWT 访问令牌,它也通过将用户 ID 存储在声明名称 sub
.
对于不透明令牌,有一个 specification defines how to get the user 's info for the resource server . It basically makes a request to the authorization server to validate the access token as well as returning the user 's info. It also mentions to use the field name sub
来引用定义为 :
Subject of the token, as defined in JWT [RFC7519]. Usually a machine-readable identifier of the resource owner who authorized this token.