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
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/configuration-model.adoc
+7-6
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ The OAuth2 authorization server `SecurityFilterChain` `@Bean` is configured with
28
28
The JWK Set endpoint is configured *only* if a `JWKSource<SecurityContext>` `@Bean` is registered.
29
29
30
30
[NOTE]
31
-
The xref:protocol-endpoints.adoc#oidc-client-registration-endpoint[OpenID Connect 1.0 Client Registration endpoint] is disabled by default.
31
+
The xref:protocol-endpoints.adoc#oidc-client-registration-endpoint[OpenID Connect 1.0 Client Registration endpoint] is disabled by default because many deployments do not require dynamic client registration.
32
32
33
33
The following example shows how to use `OAuth2AuthorizationServerConfiguration` to apply the minimal default configuration:
34
34
@@ -108,11 +108,11 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
108
108
return http.build();
109
109
}
110
110
----
111
-
<1> `registeredClientRepository()`: The xref:core-model-components.adoc#registered-client-repository[`RegisteredClientRepository`] to use.
112
-
<2> `authorizationService()`: The xref:core-model-components.adoc#oauth2-authorization-service[`OAuth2AuthorizationService`] to use.
113
-
<3> `authorizationConsentService()`: The xref:core-model-components.adoc#oauth2-authorization-consent-service[`OAuth2AuthorizationConsentService`] to use.
114
-
<4> `providerSettings()`: The <<configuring-provider-settings, `ProviderSettings`>> to use.
115
-
<5> `tokenGenerator()`: The xref:core-model-components.adoc#oauth2-token-generator[`OAuth2TokenGenerator`] to use.
111
+
<1> `registeredClientRepository()`: The xref:core-model-components.adoc#registered-client-repository[`RegisteredClientRepository`] (*REQUIRED*) for managing new and existing clients.
112
+
<2> `authorizationService()`: The xref:core-model-components.adoc#oauth2-authorization-service[`OAuth2AuthorizationService`] for managing new and existing authorizations.
113
+
<3> `authorizationConsentService()`: The xref:core-model-components.adoc#oauth2-authorization-consent-service[`OAuth2AuthorizationConsentService`] for managing new and existing authorization consents.
114
+
<4> `providerSettings()`: The <<configuring-provider-settings, `ProviderSettings`>> (*REQUIRED*) for customizing configuration settings for the OAuth2 authorization server.
115
+
<5> `tokenGenerator()`: The xref:core-model-components.adoc#oauth2-token-generator[`OAuth2TokenGenerator`] for generating tokens supported by the OAuth2 authorization server.
116
116
<6> `clientAuthentication()`: The configurer for <<configuring-client-authentication, OAuth2 Client Authentication>>.
117
117
<7> `authorizationEndpoint()`: The configurer for the xref:protocol-endpoints.adoc#oauth2-authorization-endpoint[OAuth2 Authorization endpoint].
118
118
<8> `tokenEndpoint()`: The configurer for the xref:protocol-endpoints.adoc#oauth2-token-endpoint[OAuth2 Token endpoint].
@@ -181,6 +181,7 @@ It provides access to the `ProviderSettings` and the "`current`" issuer identifi
181
181
[NOTE]
182
182
If the issuer identifier is not configured in `ProviderSettings.builder().issuer(String)`, it is resolved from the current request.
183
183
184
+
[NOTE]
184
185
The `ProviderContext` is accessible through the `ProviderContextHolder`, which associates it with the current request thread by using a `ThreadLocal`.
@@ -136,6 +137,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
136
137
}
137
138
----
138
139
140
+
[NOTE]
141
+
The `OAuth2AuthorizationServerConfigurer` is useful when applying multiple configuration options simultaneously.
142
+
139
143
[[oauth2-authorization]]
140
144
== OAuth2Authorization
141
145
@@ -144,13 +148,13 @@ An `OAuth2Authorization` is a representation of an OAuth2 authorization, which h
144
148
[TIP]
145
149
The corresponding authorization model in Spring Security's OAuth2 Client support is {spring-security-reference-base-url}/servlet/oauth2/client/core.html#oauth2Client-authorized-client[OAuth2AuthorizedClient].
146
150
147
-
After the successful completion of an authorization grant flow, an `OAuth2Authorization` is created and associates an `OAuth2AccessToken`, an (optional) `OAuth2RefreshToken`, and additional state specific to the executed authorization grant type.
151
+
After the successful completion of an authorization grant flow, an `OAuth2Authorization` is created and associates an {spring-security-api-base-url}/org/springframework/security/oauth2/core/OAuth2AccessToken.html[`OAuth2AccessToken`], an (optional) {spring-security-api-base-url}/org/springframework/security/oauth2/core/OAuth2RefreshToken.html[`OAuth2RefreshToken`], and additional state specific to the executed authorization grant type.
148
152
149
-
The `OAuth2Token` instances associated with an `OAuth2Authorization` vary, depending on the authorization grant type.
153
+
The {spring-security-api-base-url}/org/springframework/security/oauth2/core/OAuth2Token.html[`OAuth2Token`] instances associated with an `OAuth2Authorization` vary, depending on the authorization grant type.
150
154
151
155
For the OAuth2 https://datatracker.ietf.org/doc/html/rfc6749#section-4.1[authorization_code grant], an `OAuth2AuthorizationCode`, an `OAuth2AccessToken`, and an (optional) `OAuth2RefreshToken` are associated.
152
156
153
-
For the OpenID Connect 1.0 https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth[authorization_code grant], an `OAuth2AuthorizationCode`, an `OidcIdToken`, an `OAuth2AccessToken`, and an (optional) `OAuth2RefreshToken` are associated.
157
+
For the OpenID Connect 1.0 https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth[authorization_code grant], an `OAuth2AuthorizationCode`, an {spring-security-api-base-url}/org/springframework/security/oauth2/core/oidc/OidcIdToken.html[`OidcIdToken`], an `OAuth2AccessToken`, and an (optional) `OAuth2RefreshToken` are associated.
154
158
155
159
For the OAuth2 https://datatracker.ietf.org/doc/html/rfc6749#section-4.4[client_credentials grant], only an `OAuth2AccessToken` is associated.
156
160
@@ -226,6 +230,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
226
230
}
227
231
----
228
232
233
+
[NOTE]
234
+
The `OAuth2AuthorizationServerConfigurer` is useful when applying multiple configuration options simultaneously.
235
+
229
236
[[oauth2-authorization-consent]]
230
237
== OAuth2AuthorizationConsent
231
238
@@ -295,6 +302,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
295
302
}
296
303
----
297
304
305
+
[NOTE]
306
+
The `OAuth2AuthorizationServerConfigurer` is useful when applying multiple configuration options simultaneously.
307
+
298
308
[[oauth2-token-context]]
299
309
== OAuth2TokenContext
300
310
@@ -333,7 +343,7 @@ public interface OAuth2TokenContext extends Context {
333
343
<4> `getAuthorization()`: The <<oauth2-authorization, OAuth2Authorization>> associated with the authorization grant.
334
344
<5> `getAuthorizedScopes()`: The scope(s) authorized for the client.
335
345
<6> `getTokenType()`: The `OAuth2TokenType` to generate. The supported values are `code`, `access_token`, `refresh_token`, and `id_token`.
336
-
<7> `getAuthorizationGrantType()`: The `AuthorizationGrantType`.
346
+
<7> `getAuthorizationGrantType()`: The `AuthorizationGrantType` associated with the authorization grant.
337
347
<8> `getAuthorizationGrant()`: The `Authentication` instance used by the `AuthenticationProvider` that processes the authorization grant.
338
348
339
349
[[oauth2-token-generator]]
@@ -363,7 +373,9 @@ The `OAuth2AccessTokenGenerator` generates an "opaque" (`OAuth2TokenFormat.REFER
363
373
364
374
[NOTE]
365
375
The `OAuth2TokenGenerator` is an *OPTIONAL* component and defaults to a `DelegatingOAuth2TokenGenerator` composed of an `OAuth2AccessTokenGenerator` and `OAuth2RefreshTokenGenerator`.
366
-
As well, if a `JwtEncoder` `@Bean` or `JWKSource<SecurityContext>` `@Bean` is registered, then a `JwtGenerator` is additionally composed in the `DelegatingOAuth2TokenGenerator`.
376
+
377
+
[NOTE]
378
+
If a `JwtEncoder` `@Bean` or `JWKSource<SecurityContext>` `@Bean` is registered, then a `JwtGenerator` is additionally composed in the `DelegatingOAuth2TokenGenerator`.
367
379
368
380
The `OAuth2TokenGenerator` provides great flexibility, as it can support any custom token format for `access_token` and `refresh_token`.
369
381
@@ -401,6 +413,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
401
413
}
402
414
----
403
415
416
+
[NOTE]
417
+
The `OAuth2AuthorizationServerConfigurer` is useful when applying multiple configuration options simultaneously.
418
+
404
419
[[oauth2-token-customizer]]
405
420
== OAuth2TokenCustomizer
406
421
@@ -435,7 +450,7 @@ public OAuth2TokenCustomizer<OAuth2TokenClaimsContext> accessTokenCustomizer() {
435
450
}
436
451
----
437
452
438
-
[TIP]
453
+
[NOTE]
439
454
If the `OAuth2TokenGenerator` is not provided as a `@Bean` or is not configured through the `OAuth2AuthorizationServerConfigurer`, an `OAuth2TokenCustomizer<OAuth2TokenClaimsContext>` `@Bean` will automatically be configured with an `OAuth2AccessTokenGenerator`.
440
455
441
456
An `OAuth2TokenCustomizer<JwtEncodingContext>` declared with a generic type of `JwtEncodingContext` (`implements OAuth2TokenContext`) provides the ability to customize the headers and claims of a `Jwt`.
@@ -473,5 +488,8 @@ public OAuth2TokenCustomizer<JwtEncodingContext> jwtCustomizer() {
473
488
}
474
489
----
475
490
476
-
[TIP]
491
+
[NOTE]
477
492
If the `OAuth2TokenGenerator` is not provided as a `@Bean` or is not configured through the `OAuth2AuthorizationServerConfigurer`, an `OAuth2TokenCustomizer<JwtEncodingContext>` `@Bean` will automatically be configured with a `JwtGenerator`.
493
+
494
+
[TIP]
495
+
For an example showing how you can xref:guides/how-to-userinfo.adoc#customize-id-token[customize the ID token], see the guide xref:guides/how-to-userinfo.adoc#how-to-userinfo[How-to: Customize the OpenID Connect 1.0 UserInfo response].
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/guides/how-to-jpa.adoc
+21-3
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,14 @@
4
4
:docs-dir: ..
5
5
:examples-dir: ../examples
6
6
7
-
[[getting-started]]
8
-
== Getting Started
9
-
10
7
This guide shows how to implement the xref:{docs-dir}/core-model-components.adoc#core-model-components[core services] of xref:{docs-dir}/index.adoc#top[Spring Authorization Server] with JPA.
11
8
The purpose of this guide is to provide a starting point for implementing these services yourself, with the intention that you can make modifications to suit your needs.
12
9
10
+
* <<define-data-model>>
11
+
* <<create-jpa-entities>>
12
+
* <<create-spring-data-repositories>>
13
+
* <<implement-core-services>>
14
+
13
15
[[define-data-model]]
14
16
== Define the data model
15
17
@@ -20,6 +22,10 @@ NOTE: Except for token, state, metadata, settings, and claims values, we use the
20
22
In reality, the length and even type of columns you use may need to be customized.
21
23
You are encouraged to experiment and test before deploying to production.
22
24
25
+
* <<client-schema>>
26
+
* <<authorization-schema>>
27
+
* <<authorization-consent-schema>>
28
+
23
29
[[client-schema]]
24
30
=== Client Schema
25
31
@@ -69,6 +75,10 @@ The preceding schema examples provide a reference for the structure of the entit
69
75
NOTE: The following entities are minimally annotated and are just examples.
70
76
They allow the schema to be created dynamically and therefore do not require the above sql scripts to be executed manually.
By closely examining the interfaces of each core service and reviewing the `Jdbc` implementations, we can derive a minimal set of queries needed for supporting a JPA version of each interface.
109
119
120
+
* <<client-repository>>
121
+
* <<authorization-repository>>
122
+
* <<authorization-consent-repository>>
123
+
110
124
[[client-repository]]
111
125
=== Client Repository
112
126
@@ -150,6 +164,10 @@ By reviewing the `Jdbc` implementations, we can derive a minimal set of internal
150
164
CAUTION: Keep in mind that writing JSON data to text columns with a fixed length has proven problematic with the `Jdbc` implementations.
151
165
While these examples continue to do so, you may need to split these fields out into a separate table or data store that supports arbitrarily long data values.
This guide shows how to customize the xref:{docs-dir}/protocol-endpoints.adoc#oidc-user-info-endpoint[User Info endpoint] of the xref:{docs-dir}/index.adoc#top[Spring Authorization Server].
10
8
The purpose of this guide is to demonstrate how to enable the endpoint and use the available customization options to produce a custom response.
11
9
10
+
* <<enable-user-info>>
11
+
* <<customize-user-info>>
12
+
12
13
[[enable-user-info]]
13
14
== Enable the User Info Endpoint
14
15
15
-
Before customizing the response, you need to enable the User Info endpoint.
16
-
In https://openid.net/specs/openid-connect-core-1_0.html#UserInfoRequest[Section 5.3.1], the OpenID Connect 1.0 Core specification states:
16
+
The xref:{docs-dir}/protocol-endpoints.adoc#oidc-user-info-endpoint[OpenID Connect 1.0 UserInfo endpoint] is an OAuth2 protected resource, which *REQUIRES* an access token to be sent as a bearer token in the https://openid.net/specs/openid-connect-core-1_0.html#UserInfoRequest[UserInfo request].
17
17
18
18
> The Access Token obtained from an OpenID Connect Authentication Request MUST be sent as a Bearer Token, per Section 2 of https://openid.net/specs/openid-connect-core-1_0.html#RFC6750[OAuth 2.0 Bearer Token Usage] [RFC6750].
19
19
20
-
The User Info endpoint requires an authenticated request using the access token (which is a JWT when using the xref:{docs-dir}/getting-started.adoc#sample.gettingStarted[Getting Started config]).
21
-
22
-
The following listing shows how to configure https://docs.spring.io/spring-security/reference/servlet/oauth2/resource-server/jwt.html[Resource Server support] and provide a `JwtDecoder` that can validate the access token to allow authenticated requests to the User Info endpoint.
20
+
Before customizing the response, you need to enable the User Info endpoint.
21
+
The following listing shows how to enable the {spring-security-reference-base-url}/servlet/oauth2/resource-server/jwt.html[OAuth2 resource server configuration].
23
22
24
23
[[sample.userinfo]]
25
24
include::code:EnableUserInfoSecurityConfig[]
@@ -37,14 +36,17 @@ This configuration provides the following:
37
36
38
37
The following sections describe some options for customizing the user info response.
39
38
39
+
* <<customize-id-token>>
40
+
* <<customize-user-info-mapper>>
41
+
40
42
[[customize-id-token]]
41
43
=== Customize the ID Token
42
44
43
45
By default, the user info response is generated by using claims from the `id_token` that are returned with the xref:{docs-dir}/protocol-endpoints.adoc#oauth2-token-endpoint[token response].
44
46
Using the default strategy, https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims[standard claims] are returned only with the user info response based on the https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims[requested scopes] during authorization.
45
47
46
48
The preferred way to customize the user info response is to add standard claims to the `id_token`.
47
-
The following listing shows how add claims to the `id_token`.
49
+
The following listing shows how to add claims to the `id_token`.
48
50
49
51
[[sample.userinfo.idtoken]]
50
52
include::code:IdTokenCustomizerConfig[]
@@ -83,7 +85,3 @@ Similar to the <<customize-id-token,example shown earlier>> where we customize c
83
85
include::code:JwtTokenCustomizerConfig[]
84
86
85
87
Whether you customize the user info response directly or use this example and customize the access token, you can look up information in a database, perform an LDAP query, make a request to another service, or use any other means of obtaining the information you want to be presented in the user info response.
86
-
87
-
== Conclusion
88
-
89
-
In this guide, you have learned how to <<enable-user-info,enable>> the xref:{docs-dir}/protocol-endpoints.adoc#oidc-user-info-endpoint[User Info endpoint] and explored various ways of customizing the response, including <<customize-id-token,customizing the ID token>> while continuing to use the built-in response and <<customize-user-info-mapper,customizing the response directly>> using a custom user info mapper.
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/how-to.adoc
+1-12
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,7 @@
2
2
= "How-to" Guides
3
3
4
4
[[how-to-overview]]
5
-
== Overview
5
+
== List of Guides
6
6
7
7
* xref:guides/how-to-userinfo.adoc[Customize the OpenID Connect 1.0 UserInfo response]
8
8
* xref:guides/how-to-jpa.adoc[Implement core services with JPA]
9
-
10
-
[[how-to-coming-soon]]
11
-
== Coming Soon
12
-
13
-
* Authenticate using social login, e.g. Google (https://github.com/spring-projects/spring-authorization-server/issues/538[#538])
14
-
* Authenticate a user in a Single Page Application with PKCE (https://github.com/spring-projects/spring-authorization-server/issues/539[#539])
15
-
* Deny access for a revoked JWT access token (https://github.com/spring-projects/spring-authorization-server/issues/543[#543])
16
-
* Provide a JWK source backed by a key rotation strategy (https://github.com/spring-projects/spring-authorization-server/issues/544[#544])
17
-
* Customize form based login (https://github.com/spring-projects/spring-authorization-server/issues/533[#533])
18
-
* Add a custom grant type (https://github.com/spring-projects/spring-authorization-server/issues/686[#686])
19
-
* Authenticate a user with two-factor authentication (https://github.com/spring-projects/spring-authorization-server/issues/534[#534])
Copy file name to clipboardExpand all lines: docs/src/docs/asciidoc/protocol-endpoints.adoc
+6
Original file line number
Diff line number
Diff line change
@@ -271,6 +271,9 @@ public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
271
271
[NOTE]
272
272
A `JwtDecoder` `@Bean` is *REQUIRED* for the OpenID Connect 1.0 UserInfo endpoint.
273
273
274
+
[TIP]
275
+
The guide xref:guides/how-to-userinfo.adoc#how-to-userinfo[How-to: Customize the OpenID Connect 1.0 UserInfo response] contains examples of customizing the UserInfo endpoint.
@@ -295,6 +298,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
295
298
}
296
299
----
297
300
301
+
[NOTE]
302
+
The OpenID Connect 1.0 Client Registration endpoint is disabled by default because many deployments do not require dynamic client registration.
303
+
298
304
`OidcClientRegistrationEndpointConfigurer` configures the `OidcClientRegistrationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
299
305
`OidcClientRegistrationEndpointFilter` is the `Filter` that processes https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest[Client Registration requests] and returns the https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationResponse[OidcClientRegistration response].
0 commit comments