You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
48
52
49
53
[NOTE]
54
+
====
50
55
The `AuthorizationCodeReactiveOAuth2AuthorizedClientProvider` is an implementation of `ReactiveOAuth2AuthorizedClientProvider` for the Authorization Code grant,
51
56
which also initiates the Authorization Request redirect by the `OAuth2AuthorizationRequestRedirectWebFilter`.
57
+
====
52
58
53
59
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:
54
60
@@ -74,7 +80,9 @@ If the client is running in an untrusted environment (eg. native application or
74
80
. `client-authentication-method` is set to "none" (`ClientAuthenticationMethod.NONE`)
75
81
76
82
[TIP]
83
+
====
77
84
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
+
====
78
86
79
87
[[oauth2-client-authorization-code-redirect-uri]]
80
88
[[oauth2Client-auth-code-redirect-uri]]The `DefaultServerOAuth2AuthorizationRequestResolver` also supports `URI` template variables for the `redirect-uri` using `UriComponentsBuilder`.
@@ -95,7 +103,9 @@ spring:
95
103
----
96
104
97
105
[NOTE]
106
+
====
98
107
`+{baseUrl}+` resolves to `+{baseScheme}://{baseHost}{basePort}{basePath}+`
108
+
====
99
109
100
110
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].
101
111
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
224
234
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.
225
235
226
236
[TIP]
237
+
====
227
238
`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
+
====
228
240
229
241
The following example shows a variation of `authorizationRequestCustomizer()` from the preceding example, and instead overrides the `OAuth2AuthorizationRequest.authorizationRequestUri` property.
230
242
@@ -263,7 +275,9 @@ private fun authorizationRequestCustomizer(): Consumer<OAuth2AuthorizationReques
263
275
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).
264
276
265
277
[TIP]
278
+
====
266
279
The `OAuth2AuthorizationRequest` is used to correlate and validate the Authorization Response.
280
+
====
267
281
268
282
The default implementation of `ServerAuthorizationRequestRepository` is `WebSessionOAuth2ServerAuthorizationRequestRepository`, which stores the `OAuth2AuthorizationRequest` in the `WebSession`.
269
283
@@ -318,7 +332,9 @@ class OAuth2ClientSecurityConfig {
318
332
=== Requesting an Access Token
319
333
320
334
[NOTE]
335
+
====
321
336
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
+
====
322
338
323
339
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.
324
340
@@ -400,13 +416,17 @@ class OAuth2ClientSecurityConfig {
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
+
====
404
422
405
423
[[oauth2-client-refresh-token-access-token]]
406
424
=== Refreshing an Access Token
407
425
408
426
[NOTE]
427
+
====
409
428
Please refer to the https://tools.ietf.org/html/rfc6749#section-6[Access Token Request/Response] protocol flow for the Refresh Token grant.
429
+
====
410
430
411
431
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.
`ReactiveOAuth2AuthorizedClientProviderBuilder.builder().refreshToken()` configures a `RefreshTokenReactiveOAuth2AuthorizedClientProvider`,
468
489
which is an implementation of a `ReactiveOAuth2AuthorizedClientProvider` for the Refresh Token grant.
490
+
====
469
491
470
492
The `OAuth2RefreshToken` may optionally be returned in the Access Token Response for the `authorization_code` and `password` grant types.
471
493
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
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
+
====
478
502
479
503
[[oauth2-client-client-credentials-access-token]]
480
504
=== Requesting an Access Token
481
505
482
506
[NOTE]
507
+
====
483
508
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
+
====
484
510
485
511
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.
`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.
@@ -662,20 +689,26 @@ class OAuth2ClientController {
662
689
======
663
690
664
691
[NOTE]
692
+
====
665
693
`ServerWebExchange` is an OPTIONAL attribute.
666
694
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`.
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
+
====
673
704
674
705
[[oauth2-client-password-access-token]]
675
706
=== Requesting an Access Token
676
707
677
708
[NOTE]
709
+
====
678
710
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
+
====
679
712
680
713
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.
@@ -910,20 +945,26 @@ class OAuth2ClientController {
910
945
======
911
946
912
947
[NOTE]
948
+
====
913
949
`ServerWebExchange` is an OPTIONAL attribute.
914
950
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
+
====
915
952
916
953
[[oauth2-client-jwt-bearer]]
917
954
== [[oauth2Client-jwt-bearer-grant]]JWT Bearer
918
955
919
956
[NOTE]
957
+
====
920
958
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
+
====
921
960
922
961
[[oauth2-client-jwt-bearer-access-token]]
923
962
=== Requesting an Access Token
924
963
925
964
[NOTE]
965
+
====
926
966
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
+
====
927
968
928
969
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.
929
970
@@ -1108,22 +1149,30 @@ class OAuth2ResourceServerController {
1108
1149
======
1109
1150
1110
1151
[NOTE]
1152
+
====
1111
1153
`JwtBearerReactiveOAuth2AuthorizedClientProvider` resolves the `Jwt` assertion via `OAuth2AuthorizationContext.getPrincipal().getPrincipal()` by default, hence the use of `JwtAuthenticationToken` in the preceding example.
1154
+
====
1112
1155
1113
1156
[TIP]
1157
+
====
1114
1158
If you need to resolve the `Jwt` assertion from a different source, you can provide `JwtBearerReactiveOAuth2AuthorizedClientProvider.setJwtAssertionResolver()` with a custom `Function<OAuth2AuthorizationContext, Mono<Jwt>>`.
Please refer to OAuth 2.0 Token Exchange for further details on the https://datatracker.ietf.org/doc/html/rfc8693[Token Exchange] grant.
1167
+
====
1121
1168
1122
1169
[[oauth2-client-token-exchange-access-token]]
1123
1170
=== Requesting an Access Token
1124
1171
1125
1172
[NOTE]
1173
+
====
1126
1174
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
+
====
1127
1176
1128
1177
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.
1129
1178
@@ -1308,11 +1357,17 @@ class OAuth2ResourceServerController {
1308
1357
======
1309
1358
1310
1359
[NOTE]
1360
+
====
1311
1361
`TokenExchangeReactiveOAuth2AuthorizedClientProvider` resolves the subject token (as an `OAuth2Token`) via `OAuth2AuthorizationContext.getPrincipal().getPrincipal()` by default, hence the use of `JwtAuthenticationToken` in the preceding example.
1312
1362
An actor token is not resolved by default.
1363
+
====
1313
1364
1314
1365
[TIP]
1366
+
====
1315
1367
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
+
====
1316
1369
1317
1370
[TIP]
1371
+
====
1318
1372
If you need to resolve an actor token, you can provide `TokenExchangeReactiveOAuth2AuthorizedClientProvider.setActorTokenResolver()` with a custom `Function<OAuth2AuthorizationContext, Mono<OAuth2Token>>`.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/reactive/oauth2/client/authorized-clients.adoc
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -227,7 +227,9 @@ fun webClient(authorizedClientManager: ReactiveOAuth2AuthorizedClientManager): W
227
227
======
228
228
229
229
[WARNING]
230
+
====
230
231
It is recommended to be cautious with this feature since all HTTP requests will receive the access token.
232
+
====
231
233
232
234
Alternatively, if `setDefaultClientRegistrationId("okta")` is configured with a valid `ClientRegistration`, the `OAuth2AccessToken` associated with the `OAuth2AuthorizedClient` is used.
233
235
@@ -266,4 +268,6 @@ fun webClient(authorizedClientManager: ReactiveOAuth2AuthorizedClientManager): W
266
268
======
267
269
268
270
[WARNING]
271
+
====
269
272
It is recommended to be cautious with this feature since all HTTP requests will receive the access token.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/reactive/oauth2/client/client-authentication.adoc
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,9 @@ spring:
82
82
== [[oauth2Client-jwt-bearer-auth]]JWT Bearer
83
83
84
84
[NOTE]
85
+
====
85
86
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
+
====
86
88
87
89
The default implementation for JWT Bearer Client Authentication is `NimbusJwtClientAuthenticationParametersConverter`,
88
90
which is a `Converter` that customizes the Token Request parameters by adding
@@ -290,5 +292,7 @@ spring:
290
292
----
291
293
292
294
[NOTE]
295
+
====
293
296
Public Clients are supported using https://tools.ietf.org/html/rfc7636[Proof Key for Code Exchange] (PKCE).
294
297
PKCE will automatically be used when `client-authentication-method` is set to "none" (`ClientAuthenticationMethod.NONE`).
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/reactive/oauth2/client/core.adoc
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,13 +97,17 @@ As an alternative, you can use `ClientRegistrations.fromOidcIssuerLocation()` to
97
97
The `ReactiveClientRegistrationRepository` serves as a repository for OAuth 2.0 / OpenID Connect 1.0 `ClientRegistration`(s).
98
98
99
99
[NOTE]
100
+
====
100
101
Client registration information is ultimately stored and owned by the associated Authorization Server.
101
102
This repository provides the ability to retrieve a sub-set of the primary client registration information, which is stored with the Authorization Server.
103
+
====
102
104
103
105
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`.
104
106
105
107
[NOTE]
108
+
====
106
109
The default implementation of `ReactiveClientRegistrationRepository` is `InMemoryReactiveClientRegistrationRepository`.
110
+
====
107
111
108
112
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.
109
113
@@ -213,15 +217,19 @@ class OAuth2ClientController {
213
217
======
214
218
215
219
[NOTE]
220
+
====
216
221
Spring Boot auto-configuration registers an `ServerOAuth2AuthorizedClientRepository` and/or `ReactiveOAuth2AuthorizedClientService` `@Bean` in the `ApplicationContext`.
217
222
However, the application may choose to override and register a custom `ServerOAuth2AuthorizedClientRepository` or `ReactiveOAuth2AuthorizedClientService` `@Bean`.
223
+
====
218
224
219
225
The default implementation of `ReactiveOAuth2AuthorizedClientService` is `InMemoryReactiveOAuth2AuthorizedClientService`, which stores `OAuth2AuthorizedClient`(s) in-memory.
220
226
221
227
Alternatively, the R2DBC implementation `R2dbcReactiveOAuth2AuthorizedClientService` may be configured for persisting `OAuth2AuthorizedClient`(s) in a database.
222
228
223
229
[NOTE]
230
+
====
224
231
`R2dbcReactiveOAuth2AuthorizedClientService` depends on the table definition described in xref:servlet/appendix/database-schema.adoc#dbschema-oauth2-client[ OAuth 2.0 Client Schema].
0 commit comments