资源服务器的 OAuth2.0 访问令牌验证
OAuth2.0 Access token validation by Resource server
我正在尝试在一个基于 java 的 Web 项目中实施 OAuth2.0 授权框架。
我使用 MS Azure 作为资源所有者(R.O) + Auth Server(A.S).
我还创建了一些要包含在访问令牌中的自定义范围(即属性)。
我的问题是 - when client receives access token from Azure AD and forwards it to the Resource Server, how does resource server(RS) validates this access token ? How can RS decode the token and read the "scope".
RS 从未连接到 R.O 或 A.S。
注意。我不想使用 OIDC。我只想通过 OAuth2
来实现
以下是目前我能看到的两个选项:
Client sends RS are pre-provisioned with client_id and client_secret.
Client_Id and client_secret shall be generated by
Azure AD when subscriber registers the APP. When client sends
access token to RS, client also includes the "code" it received from
Azure AD (i.e. Resource Owner which is Azure AD). RS can now trigger a
GET request with the "code" + client_id. Azure AD can then issue an
access token back to the RS. Here RS can map the checksum and verify
if the access token is same(i.e. authorized).
Client sends access token to RS. RS decodes the token with base64 and only checks the expiry and client Id.
If the expiry is valid and client Id is same then RS concludes the token to be valid.
1st option seems to be more secured where RS can validate the access token and can also refresh the tokens if required.
我假设您在这里指的令牌是 JWT
令牌。解码 JWT
令牌没什么大不了的,因为令牌只是 Base64 编码的。
但是验证令牌很重要。
有两种验证令牌的方法(令牌是完整的且未在两者之间进行调整):
- 如果令牌是使用对称算法(HS256,...)签名的,那么 RS 需要使用与 AS 使用的相同的密钥。我想,在你的情况下,这是不可能的。因为你不会带钥匙。
- 如果令牌是使用非对称算法(RS256,...)签名的。 AS 将使用 'private key' 对令牌进行签名,RS 将使用相应的 public 密钥来验证令牌。
注意:非对称密钥算法是 CPU RS 验证令牌的密集型任务。
我正在尝试在一个基于 java 的 Web 项目中实施 OAuth2.0 授权框架。 我使用 MS Azure 作为资源所有者(R.O) + Auth Server(A.S).
我还创建了一些要包含在访问令牌中的自定义范围(即属性)。
我的问题是 - when client receives access token from Azure AD and forwards it to the Resource Server, how does resource server(RS) validates this access token ? How can RS decode the token and read the "scope".
RS 从未连接到 R.O 或 A.S。
注意。我不想使用 OIDC。我只想通过 OAuth2
来实现以下是目前我能看到的两个选项:
Client sends RS are pre-provisioned with client_id and client_secret.
Client_Id and client_secret shall be generated by Azure AD when subscriber registers the APP. When client sends access token to RS, client also includes the "code" it received from Azure AD (i.e. Resource Owner which is Azure AD). RS can now trigger a GET request with the "code" + client_id. Azure AD can then issue an access token back to the RS. Here RS can map the checksum and verify if the access token is same(i.e. authorized).Client sends access token to RS. RS decodes the token with base64 and only checks the expiry and client Id. If the expiry is valid and client Id is same then RS concludes the token to be valid.
1st option seems to be more secured where RS can validate the access token and can also refresh the tokens if required.
我假设您在这里指的令牌是 JWT
令牌。解码 JWT
令牌没什么大不了的,因为令牌只是 Base64 编码的。
但是验证令牌很重要。
有两种验证令牌的方法(令牌是完整的且未在两者之间进行调整):
- 如果令牌是使用对称算法(HS256,...)签名的,那么 RS 需要使用与 AS 使用的相同的密钥。我想,在你的情况下,这是不可能的。因为你不会带钥匙。
- 如果令牌是使用非对称算法(RS256,...)签名的。 AS 将使用 'private key' 对令牌进行签名,RS 将使用相应的 public 密钥来验证令牌。
注意:非对称密钥算法是 CPU RS 验证令牌的密集型任务。