diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 017c74d56b..ab736b7fad 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2900,7 +2900,7 @@ You can register multiple OAuth2 clients and providers under the spring.security.oauth2.client.registration.my-client-1.client-name=Client for user scope spring.security.oauth2.client.registration.my-client-1.provider=my-oauth-provider spring.security.oauth2.client.registration.my-client-1.scope=user - spring.security.oauth2.client.registration.my-client-1.redirect-uri=http://my-redirect-uri.com + spring.security.oauth2.client.registration.my-client-1.redirect-uri-template=http://my-redirect-uri.com spring.security.oauth2.client.registration.my-client-1.client-authentication-method=basic spring.security.oauth2.client.registration.my-client-1.authorization-grant-type=authorization_code @@ -2909,7 +2909,7 @@ You can register multiple OAuth2 clients and providers under the spring.security.oauth2.client.registration.my-client-2.client-name=Client for email scope spring.security.oauth2.client.registration.my-client-2.provider=my-oauth-provider spring.security.oauth2.client.registration.my-client-2.scope=email - spring.security.oauth2.client.registration.my-client-2.redirect-uri=http://my-redirect-uri.com + spring.security.oauth2.client.registration.my-client-2.redirect-uri-template=http://my-redirect-uri.com spring.security.oauth2.client.registration.my-client-2.client-authentication-method=basic spring.security.oauth2.client.registration.my-client-2.authorization-grant-type=authorization_code @@ -2920,6 +2920,28 @@ You can register multiple OAuth2 clients and providers under the spring.security.oauth2.client.provider.my-oauth-provider.user-name-attribute=name ---- +By default, Spring Security's `OAuth2LoginAuthenticationFilter` will only process URLs matching +`/login/oauth2/code/*`. If you want to customize the `redirect-uri-template` to use a different pattern, +you will need to provide configuration to process that custom pattern. For example, you can add your own +`WebSecurityConfigurerAdapter` that looks like this: + +[source,java,indent=0] +---- +public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .anyRequest().authenticated() + .and() + .oauth2Login() + .redirectionEndpoint() + .baseUri("/custom-callback"); + } +} +---- + For common OAuth2 and OpenID providers such as Google, Github, Facebook, and Okta, we provide a set of provider defaults (`google`, `github`, `facebook`, and `okta` respectively). diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc b/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc index 5a041156f9..8da6508883 100644 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc +++ b/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc @@ -2,7 +2,7 @@ == Register Github OAuth2 application To run the sample, you need to link:https://github.com/settings/applications/new[register an OAuth application on Github]. -While registering your application, ensure the Authorization callback URL is set to http://localhost:8080/oauth2/authorize/code/github. +While registering your application, ensure the Authorization callback URL is set to http://localhost:8080/login/oauth2/code/github. After completing the registration, you will have a new OAuth Application with a Client ID and Client Secret. == Configuring application.yml diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml b/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml index 17daa597b2..220007d7e4 100644 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml +++ b/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml @@ -9,11 +9,11 @@ spring: client-name: Github user provider: github scope: user - redirect_uri: http://localhost:8080/oauth2/authorize/code/github + redirect-uri-template: http://localhost:8080/login/oauth2/code/github github-client-2: client-id: ${APP-CLIENT-ID} client-secret: ${APP-CLIENT-SECRET} client-name: Github email provider: github scope: user:email - redirect_uri: http://localhost:8080/oauth2/authorize/code/github \ No newline at end of file + redirect-uri-template: http://localhost:8080/login/oauth2/code/github \ No newline at end of file