在 Java 中解析 ADFS 令牌
Parse ADFS token in Java
我使用 ADFS 在 Web 应用程序中设置登录。
授权请求如下所示:
ADFS 执行授权并重定向到应用:
http://ruleman.net/authorize?code=aaaaaaaa.bbbbbbbbb.ccccccccc
从code参数中知道token包含了诸如username等声明。如何解码token并提取声明?
流程遵循OAuth 2.0标准。请注意,我不是 ADFS 方面的专家,但我很了解 OAuth 2.0。
授权流程由具有不同步骤的多个选项组成。在您的情况下,您使用的是 code 配置文件(指定 response_type=code)。您所做的授权步骤只是第一步,后面还有几个步骤
您可以在 "OAuth 2.0 with ADFS" 上搜索,例如http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html
授权请求
../authorize?response_type=code&client_id=ruleman
&resource=urn:ruleman:1&redirect_uri=http://ruleman.net/authorize
您将收到一个 OAuth 代码(通常没有任何信息价值,它只是一个代码)
http://ruleman.net/authorize?code=aaaaaaaa.bbbbbbbbb.ccccccccc
code parameter contains claims such as username etc
这是错误的假设
使用此代码,您需要从后端调用令牌服务以接收访问令牌(例如,使用 HttpClient)。
POST /adfs/oauth2/token HTTP/1.1
grant_type=authorization_code&client_id=some-uid-or-
other&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2FgetAToken&code=thecode
您将收到一个访问令牌。此步骤确保您的应用程序真正通过它知道的身份提供者进行了身份验证。
根据上面的 post 链接:
The interesting bit is the itself, it is in fact a JSON Web Token (JWT). That’s to say a signed representation of the user’s identity and other grants.
我无法确认,但你可以试试。通常(对于其他身份提供者)令牌只是一个令牌,客户端需要调用 "user information" 服务来获取任何用户身份声明,但是 ADFS 似乎为您提供了一些快捷方式。
然后您可以使用任何 JWT 库来 decode/validate jwt 令牌 (com.auth0/java-jwt/3.0.1)
com.auth0.jwt.interfaces.DecodedJWT jwt = com.auth0.jwt.JWT.decode(token);
此 Postman 流程 - 参考 Postman : Authorisation Code Grant on Server 2016 - ADFS 4.0。
此代码授权就是您所描述的流程。
根据其他答案:
- 使用授权端点
- 获取代码
- 将代码发送到令牌端点
- 获取 JWT
使用 jwt.io 检查 JWT。
我使用 ADFS 在 Web 应用程序中设置登录。
授权请求如下所示:
ADFS 执行授权并重定向到应用:
http://ruleman.net/authorize?code=aaaaaaaa.bbbbbbbbb.ccccccccc
从code参数中知道token包含了诸如username等声明。如何解码token并提取声明?
流程遵循OAuth 2.0标准。请注意,我不是 ADFS 方面的专家,但我很了解 OAuth 2.0。
授权流程由具有不同步骤的多个选项组成。在您的情况下,您使用的是 code 配置文件(指定 response_type=code)。您所做的授权步骤只是第一步,后面还有几个步骤
您可以在 "OAuth 2.0 with ADFS" 上搜索,例如http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html
授权请求
../authorize?response_type=code&client_id=ruleman &resource=urn:ruleman:1&redirect_uri=http://ruleman.net/authorize
您将收到一个 OAuth 代码(通常没有任何信息价值,它只是一个代码)
http://ruleman.net/authorize?code=aaaaaaaa.bbbbbbbbb.ccccccccc
code parameter contains claims such as username etc
这是错误的假设
使用此代码,您需要从后端调用令牌服务以接收访问令牌(例如,使用 HttpClient)。
POST /adfs/oauth2/token HTTP/1.1
grant_type=authorization_code&client_id=some-uid-or-
other&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2FgetAToken&code=thecode
您将收到一个访问令牌。此步骤确保您的应用程序真正通过它知道的身份提供者进行了身份验证。
根据上面的 post 链接:
The interesting bit is the itself, it is in fact a JSON Web Token (JWT). That’s to say a signed representation of the user’s identity and other grants.
我无法确认,但你可以试试。通常(对于其他身份提供者)令牌只是一个令牌,客户端需要调用 "user information" 服务来获取任何用户身份声明,但是 ADFS 似乎为您提供了一些快捷方式。
然后您可以使用任何 JWT 库来 decode/validate jwt 令牌 (com.auth0/java-jwt/3.0.1)
com.auth0.jwt.interfaces.DecodedJWT jwt = com.auth0.jwt.JWT.decode(token);
此 Postman 流程 - 参考 Postman : Authorisation Code Grant on Server 2016 - ADFS 4.0。
此代码授权就是您所描述的流程。
根据其他答案:
- 使用授权端点
- 获取代码
- 将代码发送到令牌端点
- 获取 JWT
使用 jwt.io 检查 JWT。