Skip to content

Commit 4a41c02

Browse files
committed
Update redirect-uri-template in oauth sample and docs
Fixes gh-11014
1 parent d176650 commit 4a41c02

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,7 @@ You can register multiple OAuth2 clients and providers under the
29002900
spring.security.oauth2.client.registration.my-client-1.client-name=Client for user scope
29012901
spring.security.oauth2.client.registration.my-client-1.provider=my-oauth-provider
29022902
spring.security.oauth2.client.registration.my-client-1.scope=user
2903-
spring.security.oauth2.client.registration.my-client-1.redirect-uri=http://my-redirect-uri.com
2903+
spring.security.oauth2.client.registration.my-client-1.redirect-uri-template=http://my-redirect-uri.com
29042904
spring.security.oauth2.client.registration.my-client-1.client-authentication-method=basic
29052905
spring.security.oauth2.client.registration.my-client-1.authorization-grant-type=authorization_code
29062906
@@ -2909,7 +2909,7 @@ You can register multiple OAuth2 clients and providers under the
29092909
spring.security.oauth2.client.registration.my-client-2.client-name=Client for email scope
29102910
spring.security.oauth2.client.registration.my-client-2.provider=my-oauth-provider
29112911
spring.security.oauth2.client.registration.my-client-2.scope=email
2912-
spring.security.oauth2.client.registration.my-client-2.redirect-uri=http://my-redirect-uri.com
2912+
spring.security.oauth2.client.registration.my-client-2.redirect-uri-template=http://my-redirect-uri.com
29132913
spring.security.oauth2.client.registration.my-client-2.client-authentication-method=basic
29142914
spring.security.oauth2.client.registration.my-client-2.authorization-grant-type=authorization_code
29152915
@@ -2920,6 +2920,28 @@ You can register multiple OAuth2 clients and providers under the
29202920
spring.security.oauth2.client.provider.my-oauth-provider.user-name-attribute=name
29212921
----
29222922

2923+
By default, Spring Security's `OAuth2LoginAuthenticationFilter` will only process URLs matching
2924+
`/login/oauth2/code/*`. If you want to customize the `redirect-uri-template` to use a different pattern,
2925+
you will need to provide configuration to process that custom pattern. For example, you can add your own
2926+
`WebSecurityConfigurerAdapter` that looks like this:
2927+
2928+
[source,java,indent=0]
2929+
----
2930+
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
2931+
2932+
@Override
2933+
protected void configure(HttpSecurity http) throws Exception {
2934+
http
2935+
.authorizeRequests()
2936+
.anyRequest().authenticated()
2937+
.and()
2938+
.oauth2Login()
2939+
.redirectionEndpoint()
2940+
.baseUri("/custom-callback");
2941+
}
2942+
}
2943+
----
2944+
29232945
For common OAuth2 and OpenID providers such as Google, Github, Facebook, and Okta,
29242946
we provide a set of provider defaults (`google`, `github`, `facebook`, and `okta`
29252947
respectively).

spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
== Register Github OAuth2 application
44
To run the sample, you need to link:https://github.com/settings/applications/new[register an OAuth application on Github].
5-
While registering your application, ensure the Authorization callback URL is set to http://localhost:8080/oauth2/authorize/code/github.
5+
While registering your application, ensure the Authorization callback URL is set to http://localhost:8080/login/oauth2/code/github.
66
After completing the registration, you will have a new OAuth Application with a Client ID and Client Secret.
77

88
== Configuring application.yml

spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ spring:
99
client-name: Github user
1010
provider: github
1111
scope: user
12-
redirect_uri: http://localhost:8080/oauth2/authorize/code/github
12+
redirect-uri-template: http://localhost:8080/login/oauth2/code/github
1313
github-client-2:
1414
client-id: ${APP-CLIENT-ID}
1515
client-secret: ${APP-CLIENT-SECRET}
1616
client-name: Github email
1717
provider: github
1818
scope: user:email
19-
redirect_uri: http://localhost:8080/oauth2/authorize/code/github
19+
redirect-uri-template: http://localhost:8080/login/oauth2/code/github

0 commit comments

Comments
 (0)