簡體   English   中英

如何在spring security oauth2中分離訪問令牌和刷新令牌端點

[英]How to separate access token and refresh token endpoint in spring security oauth2

在 spring security oauth2 中,獲取訪問令牌和刷新令牌使用相同的端點 '/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)));
        }

但我想將此端點分成兩個,例如“oauth/access_token”用於獲取訪問令牌,“oauth/refresh_token”用於refreh訪問令牌。 我該怎么做 ?

我嘗試編寫自定義端點類,並注冊 bean 以覆蓋默認的 TokenEndpoint ,但似乎效果不佳。

您可以為訪問令牌和刷新令牌創建兩個 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
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM