Our review
Reference guide for setting up a Spring Authorization Server (OAuth 2.1 / OpenID Connect): security filter chains, client registration, and token issuance.
Strengths
- Provides a copy-ready Spring Security configuration skeleton with the two ordered SecurityFilterChains and OIDC enabled
- Includes a complete RegisteredClient example with mandatory PKCE, short TTLs, and refresh token rotation
- Compact best-practice table covering PKCE, short-lived tokens, and key storage
- Explicitly redirects to sibling skills for OAuth2 client and resource server concerns
Limitations
- The main file is deliberately short: JPA client persistence, custom claims, userinfo endpoint, and revocation live in advanced.md
- Assumes prior working knowledge of Spring Security and OAuth2/OIDC flows
- Java/XML snippets only; no Kotlin or Gradle variants
Use it when building or debugging a server-side OAuth 2.1 / OIDC provider with Spring Boot, including client registration and JWT issuance.
Do not use it to configure an OAuth2 client application or to validate JWTs on a resource server — the spring-security skill covers those.
Security analysis
SafeThe skill is a documentation/reference file containing configuration examples for Spring Authorization Server. It does not instruct destructive actions, data exfiltration, or unsafe command execution. The allowed tools are limited to file operations and search. Example code includes '{noop}secret' but is clearly illustrative and accompanied by best practices and anti-pattern warnings.
No concerns found
Examples
Add a RegisteredClient to my Spring Boot authorization server for a web app called web-client using authorization_code + refresh_token, requiring PKCE, with a 15-minute access token and a 7-day rotating refresh token.Configure two ordered SecurityFilterChain beans so my Spring Authorization Server exposes the OIDC endpoints and redirects unauthenticated HTML requests to /login.Review my Spring Authorization Server token settings and tell me whether my access token TTL, refresh token reuse, and PKCE requirements follow OAuth 2.1 best practices.name: spring-authorization-server description: | Spring Authorization Server for building OAuth 2.1 and OpenID Connect providers.
USE WHEN: user mentions "OAuth2 server", "authorization server", "OIDC provider", "token endpoint", asks about "how to implement OAuth2", "create authorization server", "issue JWT tokens", "custom OAuth provider"
DO NOT USE FOR: OAuth2 client configuration - use spring-security instead, resource server JWT validation - use spring-security instead
allowed-tools: Read, Grep, Glob, Write, Edit
Spring Authorization Server - Quick Reference
Full Reference: See advanced.md for JPA client persistence, JWT configuration, custom token claims, user info endpoint, consent controller, token revocation, resource server integration, and testing.
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:spring-authorization-serverfor comprehensive documentation.
Dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-authorization-server</artifactId>
</dependency>
OAuth 2.1 Flows
Authorization Code + PKCE:
Client ──(1) Authorization Request + code_challenge──▶ Auth Server
◀──(2) Authorization Code──────────────────────
──(3) Token Request + code_verifier────────────▶
◀──(4) Access Token + Refresh Token + ID Token─
Basic Configuration
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
@Order(1)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http)
throws Exception {
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
http.getConfigurer(OAuth2AuthorizationServerConfigurer.class)
.oidc(Customizer.withDefaults()); // Enable OpenID Connect
http.exceptionHandling(exceptions -> exceptions
.defaultAuthenticationEntryPointFor(
new LoginUrlAuthenticationEntryPoint("/login"),
new MediaTypeRequestMatcher(MediaType.TEXT_HTML)
)
)
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()));
return http.build();
}
@Bean
@Order(2)
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated())
.formLogin(Customizer.withDefaults());
return http.build();
}
}
Client Registration
@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient webClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("web-client")
.clientSecret("{noop}secret")
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.redirectUri("http://localhost:8080/login/oauth2/code/web-client")
.scope(OidcScopes.OPENID)
.scope(OidcScopes.PROFILE)
.scope("read")
.clientSettings(ClientSettings.builder()
.requireAuthorizationConsent(true)
.requireProofKey(true) // PKCE required
.build())
.tokenSettings(TokenSettings.builder()
.accessTokenTimeToLive(Duration.ofMinutes(15))
.refreshTokenTimeToLive(Duration.ofDays(7))
.reuseRefreshTokens(false)
.build())
.build();
return new InMemoryRegisteredClientRepository(webClient);
}
Best Practices
| Do | Don't | |----|-------| | Require PKCE for public clients | Allow plain authorization code | | Use short-lived access tokens | Long-lived access tokens | | Rotate refresh tokens | Reuse refresh tokens indefinitely | | Store keys securely (Vault) | Hardcode keys in config | | Validate redirect URIs strictly | Allow open redirects |
When NOT to Use This Skill
- OAuth2 Client Configuration - Use
spring-security - Resource Server - For validating JWT tokens use
spring-security - Basic Authentication - Use
spring-security - Session Management - Use
spring-session
Anti-Patterns
| Anti-Pattern | Why It's Bad | Better Approach | |-------------|--------------|-----------------| | Reusing refresh tokens | Security risk if compromised | Rotate on each use | | Long-lived access tokens | Increased exposure window | Keep to 15-30 min | | Hardcoded client secrets | Secrets in version control | Use secret management | | No PKCE for SPAs | Code interception vulnerability | Always require PKCE | | Wildcard redirect URIs | Open redirect vulnerability | Whitelist exact URIs |
Quick Troubleshooting
| Issue | Possible Cause | Solution | |-------|---------------|----------| | 401 at /oauth2/authorize | User not authenticated | Check SecurityFilterChain order | | Invalid client error | Client not registered | Verify RegisteredClientRepository | | JWKS endpoint 404 | JWKSource bean missing | Ensure JWKSource configured | | Token validation fails | Issuer mismatch | Check issuer URL matches | | PKCE validation fails | code_verifier mismatch | Verify PKCE implementation |
Production Checklist
- [ ] HTTPS everywhere
- [ ] RSA keys in secure storage
- [ ] Client secrets encrypted
- [ ] PKCE required for public clients
- [ ] Token lifetimes configured
- [ ] Consent flow implemented
- [ ] Token revocation working
- [ ] Rate limiting enabled
- [ ] Audit logging configured
Reference Documentation
Security Audit Scanner
Security
Analyzes code to detect OWASP Top 10 vulnerabilities.
OWASP Security Checklist
Security
Generates application security checklists based on the OWASP Top 10.
Threat Model Generator
Security
Generates threat model documents with STRIDE analysis.