Skip to content

Commit ea5bc28

Browse files
committed
Polish OAuth2 docs
1 parent d5cb411 commit ea5bc28

File tree

10 files changed

+142
-32
lines changed

10 files changed

+142
-32
lines changed

docs/modules/ROOT/pages/reactive/oauth2/client/authorization-grants.adoc

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ This section describes Spring Security's support for authorization grants.
77
== [[oauth2Client-auth-code-grant]]Authorization Code
88

99
[NOTE]
10+
====
1011
Please refer to the OAuth 2.0 Authorization Framework for further details on the https://tools.ietf.org/html/rfc6749#section-1.3.1[Authorization Code] grant.
12+
====
1113

1214
[[oauth2-client-authorization-code-authorization]]
1315
=== Obtaining Authorization
1416

1517
[NOTE]
18+
====
1619
Please refer to the https://tools.ietf.org/html/rfc6749#section-4.1.1[Authorization Request/Response] protocol flow for the Authorization Code grant.
20+
====
1721

1822
[[oauth2-client-authorization-code-authorization-request]]
1923
=== Initiating the Authorization Request
@@ -47,8 +51,10 @@ spring:
4751
A request with the base path `/oauth2/authorization/okta` will initiate the Authorization Request redirect by the `OAuth2AuthorizationRequestRedirectWebFilter` and ultimately start the Authorization Code grant flow.
4852

4953
[NOTE]
54+
====
5055
The `AuthorizationCodeReactiveOAuth2AuthorizedClientProvider` is an implementation of `ReactiveOAuth2AuthorizedClientProvider` for the Authorization Code grant,
5156
which also initiates the Authorization Request redirect by the `OAuth2AuthorizationRequestRedirectWebFilter`.
57+
====
5258

5359
If the OAuth 2.0 Client is a https://tools.ietf.org/html/rfc6749#section-2.1[Public Client], then configure the OAuth 2.0 Client registration as follows:
5460

@@ -74,7 +80,9 @@ If the client is running in an untrusted environment (eg. native application or
7480
. `client-authentication-method` is set to "none" (`ClientAuthenticationMethod.NONE`)
7581

7682
[TIP]
83+
====
7784
If the OAuth 2.0 Provider supports PKCE for https://tools.ietf.org/html/rfc6749#section-2.1[Confidential Clients], you may (optionally) configure it using `DefaultServerOAuth2AuthorizationRequestResolver.setAuthorizationRequestCustomizer(OAuth2AuthorizationRequestCustomizers.withPkce())`.
85+
====
7886

7987
[[oauth2-client-authorization-code-redirect-uri]]
8088
[[oauth2Client-auth-code-redirect-uri]]The `DefaultServerOAuth2AuthorizationRequestResolver` also supports `URI` template variables for the `redirect-uri` using `UriComponentsBuilder`.
@@ -95,7 +103,9 @@ spring:
95103
----
96104

97105
[NOTE]
106+
====
98107
`+{baseUrl}+` resolves to `+{baseScheme}://{baseHost}{basePort}{basePath}+`
108+
====
99109

100110
Configuring the `redirect-uri` with `URI` template variables is especially useful when the OAuth 2.0 Client is running behind a xref:features/exploits/http.adoc#http-proxy-server[Proxy Server].
101111
This ensures that the `X-Forwarded-*` headers are used when expanding the `redirect-uri`.
@@ -224,7 +234,9 @@ The preceding example shows the common use case of adding a custom parameter on
224234
Alternatively, if your requirements are more advanced, you can take full control in building the Authorization Request URI by simply overriding the `OAuth2AuthorizationRequest.authorizationRequestUri` property.
225235

226236
[TIP]
237+
====
227238
`OAuth2AuthorizationRequest.Builder.build()` constructs the `OAuth2AuthorizationRequest.authorizationRequestUri`, which represents the Authorization Request URI including all query parameters using the `application/x-www-form-urlencoded` format.
239+
====
228240

229241
The following example shows a variation of `authorizationRequestCustomizer()` from the preceding example, and instead overrides the `OAuth2AuthorizationRequest.authorizationRequestUri` property.
230242

@@ -263,7 +275,9 @@ private fun authorizationRequestCustomizer(): Consumer<OAuth2AuthorizationReques
263275
The `ServerAuthorizationRequestRepository` is responsible for the persistence of the `OAuth2AuthorizationRequest` from the time the Authorization Request is initiated to the time the Authorization Response is received (the callback).
264276

265277
[TIP]
278+
====
266279
The `OAuth2AuthorizationRequest` is used to correlate and validate the Authorization Response.
280+
====
267281

268282
The default implementation of `ServerAuthorizationRequestRepository` is `WebSessionOAuth2ServerAuthorizationRequestRepository`, which stores the `OAuth2AuthorizationRequest` in the `WebSession`.
269283

@@ -318,7 +332,9 @@ class OAuth2ClientSecurityConfig {
318332
=== Requesting an Access Token
319333

320334
[NOTE]
335+
====
321336
Please refer to the https://tools.ietf.org/html/rfc6749#section-4.1.3[Access Token Request/Response] protocol flow for the Authorization Code grant.
337+
====
322338

323339
The default implementation of `ReactiveOAuth2AccessTokenResponseClient` for the Authorization Code grant is `WebClientReactiveAuthorizationCodeTokenResponseClient`, which uses a `WebClient` for exchanging an authorization code for an access token at the Authorization Server’s Token Endpoint.
324340

@@ -400,13 +416,17 @@ class OAuth2ClientSecurityConfig {
400416
== [[oauth2Client-refresh-token-grant]]Refresh Token
401417

402418
[NOTE]
419+
====
403420
Please refer to the OAuth 2.0 Authorization Framework for further details on the https://tools.ietf.org/html/rfc6749#section-1.5[Refresh Token].
421+
====
404422

405423
[[oauth2-client-refresh-token-access-token]]
406424
=== Refreshing an Access Token
407425

408426
[NOTE]
427+
====
409428
Please refer to the https://tools.ietf.org/html/rfc6749#section-6[Access Token Request/Response] protocol flow for the Refresh Token grant.
429+
====
410430

411431
The default implementation of `ReactiveOAuth2AccessTokenResponseClient` for the Refresh Token grant is `WebClientReactiveRefreshTokenTokenResponseClient`, which uses a `WebClient` when refreshing an access token at the Authorization Server’s Token Endpoint.
412432

@@ -464,8 +484,10 @@ authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider)
464484
======
465485

466486
[NOTE]
487+
====
467488
`ReactiveOAuth2AuthorizedClientProviderBuilder.builder().refreshToken()` configures a `RefreshTokenReactiveOAuth2AuthorizedClientProvider`,
468489
which is an implementation of a `ReactiveOAuth2AuthorizedClientProvider` for the Refresh Token grant.
490+
====
469491

470492
The `OAuth2RefreshToken` may optionally be returned in the Access Token Response for the `authorization_code` and `password` grant types.
471493
If the `OAuth2AuthorizedClient.getRefreshToken()` is available and the `OAuth2AuthorizedClient.getAccessToken()` is expired, it will automatically be refreshed by the `RefreshTokenReactiveOAuth2AuthorizedClientProvider`.
@@ -474,13 +496,17 @@ If the `OAuth2AuthorizedClient.getRefreshToken()` is available and the `OAuth2Au
474496
== [[oauth2Client-client-creds-grant]]Client Credentials
475497

476498
[NOTE]
499+
====
477500
Please refer to the OAuth 2.0 Authorization Framework for further details on the https://tools.ietf.org/html/rfc6749#section-1.3.4[Client Credentials] grant.
501+
====
478502

479503
[[oauth2-client-client-credentials-access-token]]
480504
=== Requesting an Access Token
481505

482506
[NOTE]
507+
====
483508
Please refer to the https://tools.ietf.org/html/rfc6749#section-4.4.2[Access Token Request/Response] protocol flow for the Client Credentials grant.
509+
====
484510

485511
The default implementation of `ReactiveOAuth2AccessTokenResponseClient` for the Client Credentials grant is `WebClientReactiveClientCredentialsTokenResponseClient`, which uses a `WebClient` when requesting an access token at the Authorization Server’s Token Endpoint.
486512

@@ -536,8 +562,9 @@ authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider)
536562
======
537563

538564
[NOTE]
539-
`ReactiveOAuth2AuthorizedClientProviderBuilder.builder().clientCredentials()` configures a `ClientCredentialsReactiveOAuth2AuthorizedClientProvider`,
540-
which is an implementation of a `ReactiveOAuth2AuthorizedClientProvider` for the Client Credentials grant.
565+
====
566+
`ReactiveOAuth2AuthorizedClientProviderBuilder.builder().clientCredentials()` configures a `ClientCredentialsReactiveOAuth2AuthorizedClientProvider`, which is an implementation of a `ReactiveOAuth2AuthorizedClientProvider` for the Client Credentials grant.
567+
====
541568

542569
[[oauth2-client-client-credentials-authorized-client-manager]]
543570
=== Using the Access Token
@@ -662,20 +689,26 @@ class OAuth2ClientController {
662689
======
663690

664691
[NOTE]
692+
====
665693
`ServerWebExchange` is an OPTIONAL attribute.
666694
If not provided, it will be obtained from the https://projectreactor.io/docs/core/release/reference/#context[Reactor's Context] via the key `ServerWebExchange.class`.
695+
====
667696

668697
[[oauth2-client-password]]
669698
== [[oauth2Client-password-grant]]Resource Owner Password Credentials
670699

671700
[NOTE]
701+
====
672702
Please refer to the OAuth 2.0 Authorization Framework for further details on the https://tools.ietf.org/html/rfc6749#section-1.3.3[Resource Owner Password Credentials] grant.
703+
====
673704

674705
[[oauth2-client-password-access-token]]
675706
=== Requesting an Access Token
676707

677708
[NOTE]
709+
====
678710
Please refer to the https://tools.ietf.org/html/rfc6749#section-4.3.2[Access Token Request/Response] protocol flow for the Resource Owner Password Credentials grant.
711+
====
679712

680713
The default implementation of `ReactiveOAuth2AccessTokenResponseClient` for the Resource Owner Password Credentials grant is `WebClientReactivePasswordTokenResponseClient`, which uses a `WebClient` when requesting an access token at the Authorization Server’s Token Endpoint.
681714

@@ -738,8 +771,10 @@ authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider)
738771
======
739772

740773
[NOTE]
774+
====
741775
`ReactiveOAuth2AuthorizedClientProviderBuilder.builder().password()` configures a `PasswordReactiveOAuth2AuthorizedClientProvider`,
742776
which is an implementation of a `ReactiveOAuth2AuthorizedClientProvider` for the Resource Owner Password Credentials grant.
777+
====
743778

744779
[[oauth2-client-password-authorized-client-manager]]
745780
=== Using the Access Token
@@ -910,20 +945,26 @@ class OAuth2ClientController {
910945
======
911946

912947
[NOTE]
948+
====
913949
`ServerWebExchange` is an OPTIONAL attribute.
914950
If not provided, it will be obtained from the https://projectreactor.io/docs/core/release/reference/#context[Reactor's Context] via the key `ServerWebExchange.class`.
951+
====
915952

916953
[[oauth2-client-jwt-bearer]]
917954
== [[oauth2Client-jwt-bearer-grant]]JWT Bearer
918955

919956
[NOTE]
957+
====
920958
Please refer to JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants for further details on the https://datatracker.ietf.org/doc/html/rfc7523[JWT Bearer] grant.
959+
====
921960

922961
[[oauth2-client-jwt-bearer-access-token]]
923962
=== Requesting an Access Token
924963

925964
[NOTE]
965+
====
926966
Please refer to the https://datatracker.ietf.org/doc/html/rfc7523#section-2.1[Access Token Request/Response] protocol flow for the JWT Bearer grant.
967+
====
927968

928969
The default implementation of `ReactiveOAuth2AccessTokenResponseClient` for the JWT Bearer grant is `WebClientReactiveJwtBearerTokenResponseClient`, which uses a `WebClient` when requesting an access token at the Authorization Server’s Token Endpoint.
929970

@@ -1108,22 +1149,30 @@ class OAuth2ResourceServerController {
11081149
======
11091150

11101151
[NOTE]
1152+
====
11111153
`JwtBearerReactiveOAuth2AuthorizedClientProvider` resolves the `Jwt` assertion via `OAuth2AuthorizationContext.getPrincipal().getPrincipal()` by default, hence the use of `JwtAuthenticationToken` in the preceding example.
1154+
====
11121155

11131156
[TIP]
1157+
====
11141158
If you need to resolve the `Jwt` assertion from a different source, you can provide `JwtBearerReactiveOAuth2AuthorizedClientProvider.setJwtAssertionResolver()` with a custom `Function<OAuth2AuthorizationContext, Mono<Jwt>>`.
1159+
====
11151160

11161161
[[oauth2-client-token-exchange]]
11171162
== [[oauth2Client-token-exchange-grant]]Token Exchange
11181163

11191164
[NOTE]
1165+
====
11201166
Please refer to OAuth 2.0 Token Exchange for further details on the https://datatracker.ietf.org/doc/html/rfc8693[Token Exchange] grant.
1167+
====
11211168

11221169
[[oauth2-client-token-exchange-access-token]]
11231170
=== Requesting an Access Token
11241171

11251172
[NOTE]
1173+
====
11261174
Please refer to the https://datatracker.ietf.org/doc/html/rfc8693#section-2[Token Exchange Request and Response] protocol flow for the Token Exchange grant.
1175+
====
11271176

11281177
The default implementation of `ReactiveOAuth2AccessTokenResponseClient` for the Token Exchange grant is `WebClientReactiveTokenExchangeTokenResponseClient`, which uses a `WebClient` when requesting an access token at the Authorization Server’s Token Endpoint.
11291178

@@ -1308,11 +1357,17 @@ class OAuth2ResourceServerController {
13081357
======
13091358

13101359
[NOTE]
1360+
====
13111361
`TokenExchangeReactiveOAuth2AuthorizedClientProvider` resolves the subject token (as an `OAuth2Token`) via `OAuth2AuthorizationContext.getPrincipal().getPrincipal()` by default, hence the use of `JwtAuthenticationToken` in the preceding example.
13121362
An actor token is not resolved by default.
1363+
====
13131364

13141365
[TIP]
1366+
====
13151367
If you need to resolve the subject token from a different source, you can provide `TokenExchangeReactiveOAuth2AuthorizedClientProvider.setSubjectTokenResolver()` with a custom `Function<OAuth2AuthorizationContext, Mono<OAuth2Token>>`.
1368+
====
13161369

13171370
[TIP]
1371+
====
13181372
If you need to resolve an actor token, you can provide `TokenExchangeReactiveOAuth2AuthorizedClientProvider.setActorTokenResolver()` with a custom `Function<OAuth2AuthorizationContext, Mono<OAuth2Token>>`.
1373+
====

docs/modules/ROOT/pages/reactive/oauth2/client/authorized-clients.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ fun webClient(authorizedClientManager: ReactiveOAuth2AuthorizedClientManager): W
227227
======
228228

229229
[WARNING]
230+
====
230231
It is recommended to be cautious with this feature since all HTTP requests will receive the access token.
232+
====
231233

232234
Alternatively, if `setDefaultClientRegistrationId("okta")` is configured with a valid `ClientRegistration`, the `OAuth2AccessToken` associated with the `OAuth2AuthorizedClient` is used.
233235

@@ -266,4 +268,6 @@ fun webClient(authorizedClientManager: ReactiveOAuth2AuthorizedClientManager): W
266268
======
267269

268270
[WARNING]
271+
====
269272
It is recommended to be cautious with this feature since all HTTP requests will receive the access token.
273+
====

docs/modules/ROOT/pages/reactive/oauth2/client/client-authentication.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ spring:
8282
== [[oauth2Client-jwt-bearer-auth]]JWT Bearer
8383

8484
[NOTE]
85+
====
8586
Please refer to JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants for further details on https://datatracker.ietf.org/doc/html/rfc7523#section-2.2[JWT Bearer] Client Authentication.
87+
====
8688

8789
The default implementation for JWT Bearer Client Authentication is `NimbusJwtClientAuthenticationParametersConverter`,
8890
which is a `Converter` that customizes the Token Request parameters by adding
@@ -290,5 +292,7 @@ spring:
290292
----
291293

292294
[NOTE]
295+
====
293296
Public Clients are supported using https://tools.ietf.org/html/rfc7636[Proof Key for Code Exchange] (PKCE).
294297
PKCE will automatically be used when `client-authentication-method` is set to "none" (`ClientAuthenticationMethod.NONE`).
298+
====

docs/modules/ROOT/pages/reactive/oauth2/client/core.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,17 @@ As an alternative, you can use `ClientRegistrations.fromOidcIssuerLocation()` to
9797
The `ReactiveClientRegistrationRepository` serves as a repository for OAuth 2.0 / OpenID Connect 1.0 `ClientRegistration`(s).
9898

9999
[NOTE]
100+
====
100101
Client registration information is ultimately stored and owned by the associated Authorization Server.
101102
This repository provides the ability to retrieve a sub-set of the primary client registration information, which is stored with the Authorization Server.
103+
====
102104

103105
Spring Boot auto-configuration binds each of the properties under `spring.security.oauth2.client.registration._[registrationId]_` to an instance of `ClientRegistration` and then composes each of the `ClientRegistration` instance(s) within a `ReactiveClientRegistrationRepository`.
104106

105107
[NOTE]
108+
====
106109
The default implementation of `ReactiveClientRegistrationRepository` is `InMemoryReactiveClientRegistrationRepository`.
110+
====
107111

108112
The auto-configuration also registers the `ReactiveClientRegistrationRepository` as a `@Bean` in the `ApplicationContext` so that it is available for dependency-injection, if needed by the application.
109113

@@ -213,15 +217,19 @@ class OAuth2ClientController {
213217
======
214218

215219
[NOTE]
220+
====
216221
Spring Boot auto-configuration registers an `ServerOAuth2AuthorizedClientRepository` and/or `ReactiveOAuth2AuthorizedClientService` `@Bean` in the `ApplicationContext`.
217222
However, the application may choose to override and register a custom `ServerOAuth2AuthorizedClientRepository` or `ReactiveOAuth2AuthorizedClientService` `@Bean`.
223+
====
218224

219225
The default implementation of `ReactiveOAuth2AuthorizedClientService` is `InMemoryReactiveOAuth2AuthorizedClientService`, which stores `OAuth2AuthorizedClient`(s) in-memory.
220226

221227
Alternatively, the R2DBC implementation `R2dbcReactiveOAuth2AuthorizedClientService` may be configured for persisting `OAuth2AuthorizedClient`(s) in a database.
222228

223229
[NOTE]
230+
====
224231
`R2dbcReactiveOAuth2AuthorizedClientService` depends on the table definition described in xref:servlet/appendix/database-schema.adoc#dbschema-oauth2-client[ OAuth 2.0 Client Schema].
232+
====
225233

226234

227235
[[oauth2Client-authorized-manager-provider]]

0 commit comments

Comments
 (0)