This project demonstrates a minimal Spring Authorization Server (spring-auth-server) and a Spring Resource Server (resource-server) setup using JWT-based authentication. The setup is tailored for Postman-only client credentials flow, suitable for demos or learning purposes.
Spring Authorization Server is a framework from Spring for building your own OAuth2 / OpenID Connect compliant Authorization Server.
- Provides endpoints for issuing access tokens, refresh tokens, and exposing JWKS for JWT verification.
- Can be used to implement OAuth2 flows like client credentials, authorization code, password, refresh token, etc.
- Advantages over other servers like Keycloak:
- Lightweight and fully native Spring integration.
- No additional server setup or UI required (Keycloak requires standalone deployment).
- Fully customizable using Spring Security configuration.
- Great for learning and demos, or when you want a simple, embedded authorization server.
Spring is planning to integrate Spring Authorization Server fully with Spring Security 7, which will further streamline OAuth2 support directly within Spring Security.
- Basic Authorization Server using only one YAML configuration file (
application.yml). - Issues access tokens based on client credentials only — e.g., Postman can request a token; no login forms or browser interactions are required.
- Minimal setup, but extendable for:
- Multiple clients
- Different grant types (authorization code, refresh token)
- PKCE, consent screens, custom claims, roles, and scopes
spring:
security:
oauth2:
authorizationserver:
client:
postman-client:
registration:
client-id: postman-client
client-secret: "{noop}postman-secret"
client-authentication-methods: client_secret_basic
authorization-grant-types: client_credentials
scopes: read, write
require-authorization-consent: false{noop}indicates a plaintext secret for demo purposes.- Only
client_credentialsgrant type is enabled. - No login form or consent page is required.
A Resource Server is essentially a microservice exposing APIs that are protected by access tokens. Every microservice in a microservices architecture can include Resource Server logic to validate JWTs issued by the Authorization Server.
- Protects all Employee CRUD APIs (
/api/v1/employees/**). - Validates JWT tokens issued by
spring-auth-serverusing the JWKS endpoint. - Any request without a valid Bearer token is 401 Unauthorized.
spring:
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: http://localhost:9000/oauth2/jwksjwk-set-uripoints to the Authorization Server’s public keys.- Only valid tokens can access protected APIs.
URL:
POST http://localhost:9000/oauth2/token
Headers:
Authorization: Basic base64(postman-client:postman-secret)
Content-Type: application/x-www-form-urlencoded
Body:
grant_type=client_credentials&scope=read
Response Example:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "read"
}URL:
GET http://localhost:8080/api/v1/employees
Headers:
Authorization: Bearer <access_token>
Response Example:
[
{
"id": 1,
"name": "John Doe",
"department": "IT",
"salary": 50000
},
{
"id": 2,
"name": "Jane Smith",
"department": "HR",
"salary": 55000
}
]You must include a valid access token from the Authorization Server to access this API.
We provide a Postman collection for testing:
- Generate Access Token: Call
/oauth2/tokenfromspring-auth-serverusing client credentials. - Use Access Token: Call all Employee CRUD APIs in
resource-serverby setting theAuthorizationheader asBearer <access_token>.
Import the collection, set the
access_tokenvariable, and you can test all APIs step by step.
git clone <repository-url>
cd <repository-folder>cd spring-auth-server
mvn clean install
cd ../resource-server
mvn clean installcd spring-auth-server
mvn spring-boot:run
cd ../resource-server
mvn spring-boot:runspring-auth-serverruns onhttp://localhost:9000resource-serverruns onhttp://localhost:8080
- Open Postman → Import → Select
postman_collection.json - Generate an access token from the Authorization Server and set it in the collection variable
access_token.
- Call
/oauth2/tokento get a JWT token. - Use the token in all
/api/v1/employees/**requests to test CRUD operations.
- Only one grant type is supported:
client_credentials. - No login form, no authorization code flow — Postman-only demo.
- Access tokens are JWTs, validated by the Resource Server.
- YAML configuration (
application.yml) is enough for the demo setup.
- Add multiple clients with different scopes
- Enable authorization code flow for browser-based login
- Add refresh tokens, custom claims, roles, PKCE
- Integrate with database or LDAP for dynamic client/user management
- Spring Authorization Server: Issues JWT access tokens, lightweight and fully Spring-native.
- Resource Server: Protects APIs by validating JWT tokens; essentially a microservice with protected endpoints.
- Demo Setup: Postman-only client credentials flow with
/api/v1/employeesCRUD APIs. - Step-by-step instructions provided to run and test.
Free Software, by Siraj Chaudhary