繁体   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