簡體   English   中英

Spring Security OAuth2 - 向授權 URL 添加參數

[英]Spring Security OAuth2 - Add parameter to Authorization URL

我正在使用帶有 OAuth2 的 Spring Security 進行身份驗證/授權,使用以下項目。 http://projects.spring.io/spring-security-oauth/

我需要向 OAuth2 授權 url 添加參數。 我不確定我應該如何將它添加到 AuthorizationCodeResourceDetails bean 中?

問題是我想通過從客戶端站點登錄或注冊來開始用戶旅程。 客戶端將發送 OAuth 請求,在授權服務器上,我將顯示注冊表或登錄表單供用戶繼續其旅程。

默認流程只有以下參數 /oauth/authorize?client_id=[]&redirect_uri=[]&response_type=token&scope=openid+profile&state=HZSMKb

我想附加“&startPoint=register”

public OAuth2ProtectedResourceDetails googleOAuth2Details() {
    AuthorizationCodeResourceDetails googleOAuth2Details = new AuthorizationCodeResourceDetails();
    googleOAuth2Details.setAuthenticationScheme(header);
    googleOAuth2Details.setClientAuthenticationScheme(header);
    googleOAuth2Details.setClientId(clientId);
    googleOAuth2Details.setClientSecret(clientSecret);
    googleOAuth2Details.setUserAuthorizationUri(authorizationUrl);
    googleOAuth2Details.setAccessTokenUri(accessTokenUrl);

    googleOAuth2Details.setScope(asList("openid","profile"));
    return googleOAuth2Details;
}

@SuppressWarnings("SpringJavaAutowiringInspection") // Provided by Spring Boot
@Resource
private OAuth2ClientContext oAuth2ClientContext;

@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2RestOperations authCodeRestTemplate() {
    return new OAuth2RestTemplate(googleOAuth2Details(), oAuth2ClientContext);
}

由於基於 auth2“authorization_code”流程的“AuthorizationCodeResourceDetails”不接受額外的參數。 因此,為了解決這個問題,我通過在授權 url 本身中提供參數來解決這個問題。

例如。 如果授權網址是http://localhost:8080/idp/oauth/authorize

比我已將我的額外參數附加到該 url 后,如http://localhost:8080/idp/oauth/authorize?startPoint=register

由於此請求將被 Spring 保存到會話中的 SavedRequest 變量下,我稍后可以了解發起的請求是用於注冊還是登錄。

暫無
暫無

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

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