Skip to content

Commit 48344d8

Browse files
committed
Document OAuth 2.0 Login XML Support
Fixes gh-8110
1 parent 6a324c2 commit 48344d8

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

docs/manual/src/docs/asciidoc/_includes/servlet/oauth2/oauth2-login.adoc

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,10 @@ class OAuth2LoginConfig {
421421

422422
If you are not able to use Spring Boot 2.x and would like to configure one of the pre-defined providers in `CommonOAuth2Provider` (for example, Google), apply the following configuration:
423423

424-
[source,java]
424+
.OAuth2 Login Configuration
425+
====
426+
.Java
427+
[source,java,role="primary"]
425428
----
426429
@Configuration
427430
public class OAuth2LoginConfig {
@@ -465,6 +468,33 @@ public class OAuth2LoginConfig {
465468
}
466469
----
467470
471+
.Xml
472+
[source,xml,role="secondary"]
473+
----
474+
<http auto-config="true">
475+
<intercept-url pattern="/**" access="authenticated"/>
476+
<oauth2-login authorized-client-repository-ref="authorizedClientRepository"/>
477+
</http>
478+
479+
<client-registrations>
480+
<client-registration registration-id="google"
481+
client-id="google-client-id"
482+
client-secret="google-client-secret"
483+
provider-id="google"/>
484+
</client-registrations>
485+
486+
<b:bean id="authorizedClientService"
487+
class="org.springframework.security.oauth2.client.InMemoryOAuth2AuthorizedClientService"
488+
autowire="constructor"/>
489+
490+
<b:bean id="authorizedClientRepository"
491+
class="org.springframework.security.oauth2.client.web.AuthenticatedPrincipalOAuth2AuthorizedClientRepository">
492+
<b:constructor-arg ref="authorizedClientService"/>
493+
</b:bean>
494+
----
495+
====
496+
497+
468498
[[oauth2login-advanced]]
469499
=== Advanced Configuration
470500

@@ -628,6 +658,33 @@ class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
628658
----
629659
====
630660

661+
In addition to the `oauth2Login()` DSL, XML configuration is also supported.
662+
663+
The following code shows the complete configuration options available in the <<nsa-oauth2-login, security namespace>>:
664+
665+
.OAuth2 Login XML Configuration Options
666+
====
667+
[source,xml]
668+
----
669+
<http>
670+
<oauth2-login client-registration-repository-ref="clientRegistrationRepository"
671+
authorized-client-repository-ref="authorizedClientRepository"
672+
authorized-client-service-ref="authorizedClientService"
673+
authorization-request-repository-ref="authorizationRequestRepository"
674+
authorization-request-resolver-ref="authorizationRequestResolver"
675+
access-token-response-client-ref="accessTokenResponseClient"
676+
user-authorities-mapper-ref="userAuthoritiesMapper"
677+
user-service-ref="oauth2UserService"
678+
oidc-user-service-ref="oidcUserService"
679+
login-processing-url="/login/oauth2/code/*"
680+
login-page="/login"
681+
authentication-success-handler-ref="authenticationSuccessHandler"
682+
authentication-failure-handler-ref="authenticationFailureHandler"
683+
jwt-decoder-factory-ref="jwtDecoderFactory"/>
684+
</http>
685+
----
686+
====
687+
631688
The following sections go into more detail on each of the configuration options available:
632689

633690
* <<oauth2login-advanced-login-page, OAuth 2.0 Login Page>>
@@ -701,6 +758,16 @@ class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
701758
}
702759
}
703760
----
761+
762+
.Xml
763+
[source,xml,role="secondary"]
764+
----
765+
<http>
766+
<oauth2-login login-page="/login/oauth2"
767+
...
768+
/>
769+
</http>
770+
----
704771
====
705772

706773
[IMPORTANT]
@@ -771,6 +838,16 @@ class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
771838
}
772839
}
773840
----
841+
842+
.Xml
843+
[source,xml,role="secondary"]
844+
----
845+
<http>
846+
<oauth2-login login-processing-url="/login/oauth2/callback/*"
847+
...
848+
/>
849+
</http>
850+
----
774851
====
775852

776853
[IMPORTANT]
@@ -906,6 +983,16 @@ class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
906983
}
907984
}
908985
----
986+
987+
.Xml
988+
[source,xml,role="secondary"]
989+
----
990+
<http>
991+
<oauth2-login user-authorities-mapper-ref="userAuthoritiesMapper"
992+
...
993+
/>
994+
</http>
995+
----
909996
====
910997

911998
Alternatively, you may register a `GrantedAuthoritiesMapper` `@Bean` to have it automatically applied to the configuration, as shown in the following example:
@@ -1040,6 +1127,16 @@ class OAuth2LoginSecurityConfig : WebSecurityConfigurerAdapter() {
10401127
}
10411128
}
10421129
----
1130+
1131+
.Xml
1132+
[source,xml,role="secondary"]
1133+
----
1134+
<http>
1135+
<oauth2-login oidc-user-service-ref="oidcUserService"
1136+
...
1137+
/>
1138+
</http>
1139+
----
10431140
====
10441141

10451142

0 commit comments

Comments
 (0)