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/modules/ROOT/pages/servlet/oauth2/resource-server/jwt.adoc
+5-19Lines changed: 5 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,33 +40,19 @@ And that's it!
40
40
41
41
When this property and these dependencies are used, Resource Server will automatically configure itself to validate JWT-encoded Bearer Tokens.
42
42
43
-
It achieves this through a deterministic discovery process when the `JwtDecoder` is initialized from the issuer location:
43
+
It achieves this through a deterministic discovery process it launches at the first request containing a JWT:
44
44
45
45
1. Query the Provider Configuration or Authorization Server Metadata endpoint for the `jwks_url` property
46
46
2. Query the `jwks_url` endpoint for supported algorithms
47
47
3. Configure the validation strategy to query `jwks_url` for valid public keys of the algorithms found
48
48
4. Configure the validation strategy to validate each JWTs `iss` claim against `https://idp.example.com`.
49
49
50
-
In Spring Security, constructing a decoder via `JwtDecoders.fromIssuerLocation` or `NimbusJwtDecoder.withIssuerLocation(...).build()` performs this discovery immediately.
51
-
However, in Spring Boot 2.6+, the auto-configured decoder is lazy and defers discovery until the first request that contains a JWT.
52
-
This means that, by default, Resource Server startup is not coupled to the authorization server's availability.
50
+
One benefit of deferring this process is that Resource Server startup is not coupled to the authorization server's availability.
53
51
54
52
[NOTE]
55
53
====
56
-
If you want the application to fail startup when the authorization server is not available,
57
-
explicitly configure a `JwtDecoder` so that discovery happens at startup:
58
-
59
-
.Eager Validation Configuration
60
-
[source,java]
61
-
----
62
-
@Bean
63
-
JwtDecoder jwtDecoder() {
64
-
return JwtDecoders.fromIssuerLocation(issuerUri);
65
-
}
66
-
----
67
-
68
-
Otherwise, if discovery is deferred (the default in Spring Boot 2.6+),
69
-
the first request bearing a JWT will fail if the authorization server is unavailable.
54
+
This deferral is managed by javadoc:org.springframework.security.oauth2.jwt.SupplierJwtDecoder[`SupplierJwtDecoder`].
55
+
Consider wrapping any <<oauth2resourceserver-jwt-decoder,`JwtDecoder` `@Bean`>> you declare in order to preserve this behavior.
70
56
====
71
57
72
58
=== Runtime Expectations
@@ -128,7 +114,7 @@ Ultimately, the returned `JwtAuthenticationToken` will be set on the xref:servle
128
114
[[oauth2resourceserver-jwt-jwkseturi]]
129
115
== Specifying the Authorization Server JWK Set Uri Directly
130
116
131
-
If the authorization server doesn't support any configuration endpoints, or if Resource Server must be able to start up independently from the authorization server, then the `jwk-set-uri` can be supplied as well:
117
+
If the authorization server doesn't support any configuration endpoints, or if Resource Server must be able to initialize independently from the authorization server, then the `jwk-set-uri` can be supplied as well:
0 commit comments