spring-authorization-server
Easily build and configure robust OAuth 2.1 and OIDC authorization servers with Spring Security.
Install
mkdir -p .claude/skills/spring-authorization-server && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/13452" && unzip -o skill.zip -d .claude/skills/spring-authorization-server && rm skill.zipInstalls to .claude/skills/spring-authorization-server
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
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` insteadKey capabilities
- →Configure an OAuth 2.1 Authorization Server
- →Enable OpenID Connect functionality
- →Register clients with specific authentication methods and grant types
- →Define token settings like access token and refresh token lifetimes
- →Implement PKCE for public clients
- →Set up security filter chains for authorization and authentication
How it works
The skill guides the configuration of Spring Authorization Server using Java code, setting up security filter chains and client registration to enable OAuth 2.1 and OpenID Connect protocols.
Inputs & outputs
When to use spring-authorization-server
- →Implementing an OAuth2 server
- →Creating an OIDC provider
- →Issuing JWT tokens
- →Customizing token endpoints
About this skill
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
When not to use it
- →When configuring an OAuth2 client
- →When validating JWT tokens in a resource server
- →When implementing basic authentication or session management
Prerequisites
Limitations
- →Not for OAuth2 client configuration
- →Not for resource server JWT validation
- →Not for basic authentication or session management
How it compares
This skill provides specific Spring Authorization Server configurations and best practices, offering a structured approach to building an OAuth 2.1 and OpenID Connect provider compared to generic security implementations.
Compared to similar skills
spring-authorization-server side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| spring-authorization-server (this skill) | 0 | 6mo | No flags | Advanced |
| asl-java-implement-rule-authz | 0 | 2mo | No flags | Advanced |
| springboot-security | 5 | 5mo | No flags | Intermediate |
| java-pro | 34 | 4mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by claude-dev-suite
View all by claude-dev-suite →You might also like
asl-java-implement-rule-authz
ChapmanRichard
Use when: 需要在 LeaveSystem_Backend_Java 中实现认证与鉴权规则,覆盖 Header/JWT、RBAC、资源归属和默认拒绝。关键词: Java 鉴权, Spring Boot, RBAC, Authorization, 资源级权限
springboot-security
affaan-m
Spring Security best practices for authn/authz, validation, CSRF, secrets, headers, rate limiting, and dependency security in Java Spring Boot services.
java-pro
sickn33
Master Java 21+ with modern features like virtual threads, pattern matching, and Spring Boot 3.x. Expert in the latest Java ecosystem including GraalVM, Project Loom, and cloud-native patterns. Use PROACTIVELY for Java development, microservices architecture, or performance optimization.
java-coding-standards
affaan-m
Java coding standards for Spring Boot services: naming, immutability, Optional usage, streams, exceptions, generics, and project layout.
jpa-patterns
affaan-m
JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot.
backend-microservice-development
TencentBlueKing
后端微服务开发规范,涵盖目录结构、分层架构(API/Service/DAO)、依赖注入、配置管理、Spring Boot 最佳实践。当用户进行后端开发、创建新微服务、编写 Kotlin/Java 代码或设计服务架构时使用。