问题描述
我已经使用 springboot 框架实现了 Oauth2。我可以从 OAuth 服务器获取 JWT 令牌,如下所示:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsib2F1dGgyLXJlc291cmNlIl0sInVzZXJfbmFtZSI6InJycnIiLCJzY29wZSI6WyJyZWFkX3Byb2ZpbGVfaW5mbyJdLCJleHAiOjE2MTA4MTk4OTIsImF1dGhvcml0aWVzIjpbIlVTRVIiXSwianRpIjoiZDExZWIxYmMtYjUyMy00NjMxLTkxMWItMDA1Yjc1YTkyNDgwIiwiQ3VzdG9tIFBheWxvYWQiOiJycnJyLWFiY2QiLCJjbGllbnRfaWQiOiJjbGllbnRhcHaifQ.ppqpoZGTIeNaLfWCxXk9lovAjz8Vamu0ffT1pd86V_g","token_type": "bearer","refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsib2F1dGgyLXJlc291cmNlIl0sInVzZXJfbmFtZSI6InJycnIiLCJzY29wZSI6WyJyZWFkX3Byb2ZpbGVfaW5mbyJdLCJhdGkiOiJkMTFlYjFiYy1iNTIzLTQ2MzetoTExYi0wMDViNzVhOTI0ODAiLCJleHAiOjE2MTA4MjEwOTIsImF1dGhvcml0aWVzIjpbIlVTRVIiXSwianRpIjoiMzFjZWQ0OGUtZWZmOC00OGMyLWJkOTYtYjdhMjIwYmIxYjcxIiwiQ3VzdG9tIFBheWxvYWQiOiJycnJyLWFiY2QiLCJjbGllbnRfaWQiOiJjbGllbnRhcHaifQ.1u12wG4WyOmETFD-1QXrUXLO_FdJkBmxz2vX1xMHWPE","expires_in": 1199,"scope": "read_profile_info","Custom Payload": "rrrr-abcd","jti": "d11eb1bc-b523-4631-911b-005b75a92480"
}
-
虽然响应中有两个令牌,访问令牌和刷新令牌,但为什么响应对象中只有一个过期时间。
-
我厌倦了将到期时间重置为某个不同的值,但我总是看到相同的到期时间,就好像我的更改没有以某种方式反映一样。请在下面找到我用来更新访问令牌和刷新令牌到期的代码更改,但它不起作用:
@配置
@EnableAuthorizationServer public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdapter { ... @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory().withClient("clientapp").secret(passwordEncoder.encode("123456")) .authorizedGrantTypes("password","authorization_code","refresh_token").authorities("READ_ONLY_CLIENT") .scopes("read_profile_info").resourceIds("oauth2-resource").accesstokenValiditySeconds(1200) .refreshTokenValiditySeconds(2400).redirectUris("http://localhost:8080/authcode").autoApprove(true); } @Override public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception { TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(),defaultAccesstokenConverter())); endpoints.tokenStore(tokenStore()).tokenEnhancer(tokenEnhancerChain) .authenticationManager(authenticationManager); } @Bean public TokenEnhancer tokenEnhancer() { return new CustomTokenEnhancer(); } @Bean public TokenStore tokenStore() { return new JwtTokenStore(defaultAccesstokenConverter()); } @Bean public JwtAccesstokenConverter defaultAccesstokenConverter() { JwtAccesstokenConverter converter = new JwtAccesstokenConverter(); converter.setSigningKey("123"); return converter; } }
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)