Overview
The Hub API uses Auth0 OAuth2 for authentication and authorization. All API endpoints (except health checks and Swagger documentation) require a valid JWT access token.Authentication Flow
The API implements OAuth2 Resource Server pattern:- User authenticates with Auth0 (via your frontend application)
- Auth0 issues a JWT access token
- Client includes the token in API requests
- API validates the token and extracts user identity
Token Validation
The API validates JWT tokens using the following criteria:Must match the configured Auth0 issuer URI (
AUTH0_ISSUER)Must include the configured audience (
AUTH0_AUDIENCE)Token must not be expired
Token signature must be valid (verified using Auth0’s JWKS endpoint)
Audience Validation
The API implements custom audience validation to ensure tokens are intended for this API:Making Authenticated Requests
Include the JWT access token in theAuthorization header using the Bearer scheme:
User Context
Once authenticated, the API automatically:- Extracts user identity from the JWT token
- Creates or updates local user profile (via
EnsureLocalUserFilter) - Provides user context to all endpoints through
CurrentUserProvider
sub claim from the JWT is used as the user’s unique identifier.
Configuration
Configure Auth0 integration using these environment variables:Auth0 tenant issuer URIExample:
https://your-tenant.auth0.com/API identifier configured in Auth0Example:
https://api.yourdomain.comApplication Configuration
Fromapplication.yaml:
Authorization
The API implements role-based access control with the following roles:Player
Default role for authenticated users. Can create bookings, join matches, and manage own profile.
Venue Owner
Can create and manage venues, view venue bookings, and manage resources.
Admin
Full access to all endpoints including user management and system statistics.
Endpoint Patterns
/api/venues- Public endpoints (authenticated required)/api/bookings/my- Player endpoints (own resources)/api/owner/**- Venue owner endpoints/api/admin/**- Admin endpoints
Role assignment is managed through Auth0 and extracted from JWT claims. Contact your Auth0 administrator to configure roles.
Security Features
Stateless Sessions
The API uses stateless session management:Security Headers
The API enforces security best practices:Content-Security-Policy
default-src 'self'; frame-ancestors 'none'Strict-Transport-Security
max-age=31536000; includeSubDomainsCSRF Protection
CSRF protection is disabled since the API is stateless and uses Bearer token authentication:Public Endpoints
The following endpoints do NOT require authentication:GET /actuator/health- Health checkGET /v3/api-docs/**- OpenAPI documentationGET /swagger-ui/**- Swagger UI
Error Responses
401 Unauthorized
Returned when authentication token is missing or invalid:403 Forbidden
Returned when authenticated user lacks permission:Token Expiration
JWT tokens expire after a configured period (set in Auth0). When a token expires:- API returns
401 Unauthorized - Client should refresh the token using Auth0’s refresh token flow
- Retry the request with the new access token
Testing Authentication
For development and testing, you can obtain a token using Auth0’s API:For production applications, use the appropriate Auth0 SDK for your platform (Auth0 SPA SDK, Auth0 React, etc.)
Next Steps
Error Handling
Learn about error responses and status codes
API Endpoints
Explore available API endpoints