liveBook · Manning

jwkSetUri

As explained in Spring Security in Action, Second Edition

jwkSetUri is a JWT resource-server configuration method that specifies the URI from which public signing keys are obtained.

jwkSetUri configures a Spring OAuth 2 resource server with the URI of the authorization server’s JSON Web Key Set. The resource server retrieves public keys there and uses them to verify JWT signatures. section 15.1

Configure it in three steps:

  • Inject the key-set URI from configuration, such as http://localhost:8080/oauth2/jwks. section 15.1
  • Enable OAuth 2 resource-server JWT authentication and pass the URI to jwkSetUri(keySetUri). section 15.1
  • Require authentication for the protected endpoints; otherwise the endpoints remain unprotected by default. section 15.1

Resource-server configuration

http.oauth2ResourceServer(c -> c.jwt(j -> j.jwkSetUri(keySetUri))); http.authorizeHttpRequests(c -> c.anyRequest().authenticated()); section 15.1

Listing 15.5 Configuring the authentication with JWTs
@Configuration
public class ProjectConfig {

  @Value("${keySetURI}")
  private String keySetUri;

  @Bean
  public SecurityFilterChain securityFilterChain(HttpSecurity http) 
    throws Exception {

    http.oauth2ResourceServer(             #1
      c -> c.jwt(                          #2
         j -> j.jwkSetUri(keySetUri)       #3
      )
    );

    return http.build();
  }
}

Shows the nested Spring Security configuration that connects JWT authentication to the configured key-set URI. section 15.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains URI injection, nested Java configuration, key retrieval, and signature verification, without descending into validation internals.
Examples
Uses a localhost JWKS endpoint, an injected keySetURI property, and an authenticated /demo endpoint.
What it assumes
Assumes basic Spring and Java configuration, while demonstrating SecurityFilterChain and endpoint authorization setup.
What you can do after
Apply it via Spring Security’s OAuth2 resource-server JWT DSL to validate bearer access tokens.
How it connects
Connects JWT authentication with OAuth 2 resource servers, authorization servers, JSON Web Key Sets, and public-key cryptography.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.