2017-10-17 42 views
0

这里是我想要实现:春季安全的OAuth 2客户端应用程序无法检查令牌的有效性

我有一个企业的OAuth 2提供商,我想用自己的登录表单并获取代码,访问令牌所以从这个供应商

,这里是我的conf

security: 
    oauth2: 
    client: 
     clientId: MY_CLIENT_ID 
     clientSecret: asecret 
     accessTokenUri: https://blabla/oauth-server/oauth/token 
     userAuthorizationUri: https://blabla/oauth-server/oauth/authorize 
     tokenName: access_token 
     scope : read 
     userInfoUri: https://localhost/user 

我可以让我的代码,这是一个访问令牌改变,一切都很好,它调用我的本地端点,以获取用户信息(角色实例)

但是当我调试代码时,我无法在任何地方看到任何expires_in值,并且我的令牌根本没有过期。

这里是我的资源服务器的conf

@EnableResourceServer 
@EnableOAuth2Sso 
@RestController 
public class SecurityController extends ResourceServerConfigurerAdapter { 

    private static final String RESOURCE_ID = "my_rest_api"; 


    @Override 
    public void configure(ResourceServerSecurityConfigurer resources) { 
     resources.resourceId(RESOURCE_ID).stateless(true); 
    } 

    @Override 
    public void configure(HttpSecurity http) throws Exception { 
     http.requestMatchers().anyRequest().and().authorizeRequests(); 
     http. 
       anonymous().disable() 
       .requestMatchers().antMatchers("/**/*") 
       .and().authorizeRequests() 
       .antMatchers("/**/*").access("#oauth2.hasScope('read')") 
       .and().exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler()); 
    } 
} 

我不能fidn如何撤销令牌

任何想法是值得欢迎的,我已经失去了一堆小时阅读教程...

回答

0

添加access-token-validity-secondsyaml

security: 
    oauth2: 
    client: 
     clientId: MY_CLIENT_ID 
     clientSecret: asecret 
     accessTokenUri: https://blabla/oauth-server/oauth/token 
     userAuthorizationUri: https://blabla/oauth-server/oauth/authorize 
     tokenName: access_token 
     scope : read 
     userInfoUri: https://localhost/user 
     access-token-validity-seconds: 30 //Adds 30 seconds of token validity 
+0

我coud但令牌瓦利应该来自auth提供商的权利? – Seb

+0

我相信你正在使用基于内存的客户端。将令牌存储移动到某个数据库时,您可以更新每个客户端的访问令牌有效性。 –

+0

我在内存存储中的确使用了,但是我仍然从auth提供程序获取expires_in值,这应该在Spring中使用和检查,不是吗?或者有什么我不了解的? – Seb