小编Goh*_*han的帖子

Spring Security OAuth 2:如何在 oauth/token 请求后获取访问令牌和附加数据

我正在使用 Spring Security 和 Oauth 2.0 身份验证协议来保护 REST 服务。

我已经实现了一个 MVC Spring 应用程序并且它工作正常。客户端通过提供客户端凭据(client_id 和 client_secret)和用户凭据(用户名和密码)调用定义在 servlet-config.xml 中的 outh/token 服务向服务器请求 AccessToken:

<http pattern="/oauth/token" create-session="stateless"
    authentication-manager-ref="clientAuthenticationManager"
    xmlns="http://www.springframework.org/schema/security" > 
    <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
    <anonymous enabled="false" />
    <http-basic entry-point-ref="clientAuthenticationEntryPoint" />
    <custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" /> 
    <access-denied-handler ref="oauthAccessDeniedHandler" />
 </http>
Run Code Online (Sandbox Code Playgroud)

如果凭据有效,客户端将收到一个访问令牌作为响应,如下所示:

{
    "value": "b663f10d-553d-445b-afde-e9cd84066a1c",
    "expiration": 1406598295994,
    "tokenType": "bearer",
    "refreshToken": {
        "value": "36737abf-24bd-4b86-ad22-601f4d5cdee4",
        "expiration": 1408890295994
    },
    "scope": [],
    "additionalInformation": {},
    "expiresIn": 299999,
    "expired": false
}
Run Code Online (Sandbox Code Playgroud)

我想要一个响应,其中还包含这样的用户详细信息:

{
        "value": "b663f10d-553d-445b-afde-e9cd84066a1c",
        "expiration": 1406598295994,
        "tokenType": "bearer",
        "refreshToken": {
            "value": "36737abf-24bd-4b86-ad22-601f4d5cdee4", …
Run Code Online (Sandbox Code Playgroud)

spring spring-security oauth-2.0

5
推荐指数
1
解决办法
6184
查看次数

标签 统计

oauth-2.0 ×1

spring ×1

spring-security ×1