A comprehensive OAuth2 authorization server implementation supporting multiple grant types and complete user, client, and token management.
- Authorization Code Grant
- Client Credentials Grant
- Password Grant (Resource Owner Password Credentials)
- Refresh Token Grant
- Client registration and authentication
- Multiple redirect URIs support
- Grant type restrictions
- Scope-based access control
- Confidential and public client support
- User registration and authentication
- Role-based access control
- Password reset functionality
- Email verification
- Profile management
- Access token generation and validation
- Refresh token handling
- Token introspection
- Token revocation (single and bulk)
- Active session management
- Rate limiting
- Audit logging
- Session management
- Basic authentication support
- Scope-based authorization
- Token introspection
- User consent tracking
- Granular permission control
- Consent revocation
- Consent history
POST /api/v1/oauth/tokens
Authorization: Basic {client_credentials}
Content-Type: application/x-www-form-urlencoded
Supported grant types:
- Authorization Code
grant_type=authorization_code
code={authorization_code}
redirect_uri={redirect_uri}
- Client Credentials
grant_type=client_credentials
scope={scope}
- Password
grant_type=password
username={username}
password={password}
scope={scope}
- Refresh Token
grant_type=refresh_token
refresh_token={refresh_token}
POST /api/v1/oauth/introspect
Authorization: Basic {client_credentials}
Content-Type: application/x-www-form-urlencoded
token={token}
token_type_hint={access_token|refresh_token}
POST /api/v1/oauth/clients
Content-Type: application/json
{
"name": "My Application",
"redirect_uris": ["https://app.example.com/callback"],
"grant_types": ["authorization_code", "refresh_token"],
"scope": "read write",
"confidential": true
}
GET /api/v1/oauth/clients
PUT /api/v1/oauth/clients/{client_id}
DELETE /api/v1/oauth/clients/{client_id}
POST /api/v1/users
Content-Type: application/json
{
"username": "[email protected]",
"password": "secure_password",
"name": "John Doe",
"roles": ["user"]
}
PUT /api/v1/users/profile # Update user profile
POST /api/v1/users/reset-password # Reset password
POST /api/v1/users/verify-email # Verify email
GET /api/v1/users # List users (admin only)
PUT /api/v1/users/{user_id} # Update user (admin only)
DELETE /api/v1/users/{user_id} # Delete user (admin only)
POST /api/v1/oauth/scopes
Content-Type: application/json
{
"name": "read_profile",
"description": "Read user profile information"
}
GET /api/v1/oauth/scopes # List scopes
PUT /api/v1/oauth/scopes/{scope_id} # Update scope
DELETE /api/v1/oauth/scopes/{scope_id} # Delete scope
POST /api/v1/oauth/consents
Content-Type: application/json
{
"client_id": "client_id",
"scopes": ["read", "write"]
}
GET /api/v1/oauth/consents # List consents
DELETE /api/v1/oauth/consents/{consent_id} # Revoke consent
GET /api/v1/oauth/tokens # List active tokens
POST /api/v1/oauth/tokens/revoke # Revoke specific token
POST /api/v1/oauth/tokens/bulk-revoke # Bulk revoke tokens
GET /api/v1/audit-logs # View audit logs
GET /api/v1/oauth/rate-limits # Check rate limit status
GET /api/v1/oauth/sessions # List active sessions
DELETE /api/v1/oauth/sessions/{session_id} # End session
Most endpoints require authentication using HTTP Basic Authentication with client credentials:
Authorization: Basic base64(client_id:client_secret)
The API uses standard HTTP status codes and returns errors in the following format:
{
"error": "error_code",
"error_description": "Detailed error message",
"error_uri": "https://documentation/errors/error_code"
}
The API implements rate limiting per client. Current limits can be checked via the rate-limiting endpoint.
- Always use HTTPS in production
- Implement proper password hashing
- Store client secrets securely
- Implement token encryption
- Set up proper CORS configuration
- Enable audit logging
- Implement IP whitelisting where appropriate
The server requires the following database tables:
- users
- clients
- access_tokens
- refresh_tokens
- authorization_codes
- scopes
- client_scopes
- user_consents
- audit_logs