Spring OAuth2 refresh token to change after refreshing access token

会有一股神秘感。 提交于 2019-12-10 04:47:49

问题


I created an authentication server and resource server, both are working ok, the only problem is with refresh token, I would like it to change after calling POST /oauth/token with grant_type=refresh_token, however, spring returns same refresh token.

I am wondering if there is a way to get a new refresh token when calling oauth endpoint to refresh access token?


回答1:


By taking a look at refreshAccessToken method in the DefaultTokenServices class:

public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, 
                                            TokenRequest tokenRequest) {

    // Omitted
    if (!reuseRefreshToken) {
        tokenStore.removeRefreshToken(refreshToken);
        refreshToken = createRefreshToken(authentication);
    }
    // Omitted
}

You should somehow set the reuseRefreshToken flag to false. You can do that in your AuthorizationServerConfigurerAdapter implementation:

@Configuration
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {
    // Other methods

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints
                .reuseRefreshTokens(false);
    }
}


来源:https://stackoverflow.com/questions/40879729/spring-oauth2-refresh-token-to-change-after-refreshing-access-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!