Java 如何在spring security oauth2中分离访问令牌和刷新令牌端点

Java 如何在spring security oauth2中分离访问令牌和刷新令牌端点,java,spring,oauth-2.0,spring-security-oauth2,Java,Spring,Oauth 2.0,Spring Security Oauth2,在spring security oauth2中,get access token和refresh token使用相同的端点'/oauth/token',并由参数grant_type'code'或'refresh_token'识别 if (isAuthCodeRequest(parameters)) { // The scope was requested or determined during the authorization step

在spring security oauth2中,get access token和refresh token使用相同的端点'/oauth/token',并由参数grant_type'code'或'refresh_token'识别

        if (isAuthCodeRequest(parameters)) {
            // The scope was requested or determined during the authorization step
            if (!tokenRequest.getScope().isEmpty()) {
                logger.debug("Clearing scope of incoming token request");
                tokenRequest.setScope(Collections.<String> emptySet());
            }
        }

        if (isRefreshTokenRequest(parameters)) {
            // A refresh token has its own default scopes, so we should ignore any added by the factory here.
            tokenRequest.setScope(OAuth2Utils.parseParameterList(parameters.get(OAuth2Utils.SCOPE)));
        }

if(isAuthCodeRequest(参数)){
//在授权步骤中请求或确定了范围
如果(!tokenRequest.getScope().isEmpty()){
debug(“清除传入令牌请求的范围”);
tokenRequest.setScope(Collections.emptySet());
}
}
if(isRefreshTokenRequest(参数)){
//刷新令牌有其自己的默认作用域,因此我们应该忽略工厂在此处添加的任何标记。
tokenRequest.setScope(OAuth2Utils.parseParameterList(parameters.get(OAuth2Utils.SCOPE));
}
但我想把这个端点分成两部分,比如get-access-token的“oauth/access\u-token”和refreh-access-token的“oauth/refresh\u-token”。我怎么做


我曾尝试编写自定义端点类,并注册bean以覆盖默认的TokenEndpoint,但似乎效果不佳。

您可以为access token和refresh token创建两个rest控制器方法,并使用rest模板在相关控制器方法内对oauth/token端点进行标准调用

@RestController
public class TokenController {

    @RequestMapping("oauth/access_token")
    public TokenResponse getAccessToken() {
        //use rest template or httpclient to call to oauth/token and return converted TokenResponse
    }

    @RequestMapping("oauth/refresh_token")
    public TokenResponse getRefreshToken() {
        //use rest template or httpclient to call to oauth/token and return converted TokenResponse
    }
}

我已经尝试过这种方法,但rest模板的响应是401,可能端点“oauth/token”受到spring安全过滤器的保护,我将尝试对此进行配置。非常感谢。