redirect-uri property supports 'baseRedirectUrl' uri variable

Fixes gh-4589
This commit is contained in:
Joe Grandja 2017-10-02 15:29:03 -04:00
parent 66647070ab
commit fb57111ecd
3 changed files with 11 additions and 2 deletions

View File

@ -13,7 +13,7 @@ spring.security.oauth2.client.templates.google.client-alias=google
# GitHub
spring.security.oauth2.client.templates.github.client-authentication-method=basic
spring.security.oauth2.client.templates.github.authorization-grant-type=authorization_code
spring.security.oauth2.client.templates.github.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{registrationId}
spring.security.oauth2.client.templates.github.redirect-uri={baseRedirectUrl}/oauth2/authorize/code/{registrationId}
spring.security.oauth2.client.templates.github.scope=user
spring.security.oauth2.client.templates.github.authorization-uri=https://github.com/login/oauth/authorize
spring.security.oauth2.client.templates.github.token-uri=https://github.com/login/oauth/access_token

View File

@ -160,6 +160,15 @@ public class AuthorizationCodeRequestRedirectFilter extends OncePerRequestFilter
uriVariables.put("contextPath", request.getContextPath());
uriVariables.put("registrationId", clientRegistration.getRegistrationId());
String baseRedirectUrl = UriComponentsBuilder.newInstance()
.scheme(request.getScheme())
.host(request.getServerName())
.port(request.getServerPort())
.path(request.getContextPath())
.build()
.toUriString();
uriVariables.put("baseRedirectUrl", baseRedirectUrl);
return UriComponentsBuilder.fromUriString(clientRegistration.getRedirectUri())
.buildAndExpand(uriVariables)
.toUriString();

View File

@ -15,7 +15,7 @@ security:
github:
client-authentication-method: basic
authorization-grant-type: authorization_code
redirect-uri: "{scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{registrationId}"
redirect-uri: "{baseRedirectUrl}/oauth2/authorize/code/{registrationId}"
scope: user
authorization-uri: "https://github.com/login/oauth/authorize"
token-uri: "https://github.com/login/oauth/access_token"