rrezartprebreza/spring-boot-skills / skills/spring-boot-3/oauth2-resource-server
oauth2-resource-server
VerifiedUse when configuring Spring Boot as an OAuth2 resource server, validating JWTs from an external auth provider (Keycloak, Auth0, Okta, Cognito), extracting claims, or implementing scope-based authorization.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.5 KB |
| agents/openai.yaml | config | 207 B |
| examples/bad-resource-server-config.java | other | 1.7 KB |
| examples/good-resource-server-config.java | other | 1.6 KB |
| templates/ExternalIdentity.java | other | 751 B |
| templates/JwtClaimExtractor.java | other | 2.2 KB |
| templates/ResourceServerConfig.java | other | 3.3 KB |
examples/good-resource-server-config.java
View on GitHub// GOOD — JWT resource server, custom converter, scope-based auth, stateless
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class ResourceServerConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(session ->
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/products/**").hasAuthority("SCOPE_read")
.requestMatchers(HttpMethod.POST, "/api/v1/orders/**").hasAuthority("SCOPE_write")
.requestMatchers("/api/v1/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().authenticated())
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())))
.build();
}
@Bean
public JwtAuthenticationConverter jwtAuthenticationConverter() {
// Defaults read the "scope" OR "scp" claim -> SCOPE_*. Setting the claim name to
// "scope" would drop the scp fallback that Okta and Entra ID access tokens use.
JwtGrantedAuthoritiesConverter grantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
converter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);
converter.setPrincipalClaimName("sub");
return converter;
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |