这是我想要实现的目标:
我有一个企业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值,而且我的令牌根本不会过期。
这是我的资源服务器配置
@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());
}
}
我无法解决如何撤销令牌
的问题任何想法都是受欢迎的,我已经失去了一堆小时的阅读教程......
答案 0 :(得分:0)
将access-token-validity-seconds
添加到您的yaml
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