Overview
The Extracurricular Management System API uses JWT (JSON Web Token) authentication to secure endpoints. After registering or logging in, you’ll receive a token that must be included in subsequent requests.Authentication Flow
User Registration
Register a new user account. Different user roles require different fields.Endpoint
This endpoint is publicly accessible and does not require authentication.
Request Body
User’s first name
User’s last name
Valid email address (must be unique)
Password (minimum 6 characters)
User role:
STUDENT, ORGANIZER, or ADMINOptional phone number
Role-Specific Fields
For STUDENT:Student identifier (e.g., “S123456”)
Student’s major/field of study
Current year of study
Name of the organization
Department affiliation
Admin level (defaults to
STANDARD_ADMIN for public registration)Registration Examples
Registration Response
User Login
Authenticate with existing credentials to receive a JWT token.Endpoint
This endpoint is publicly accessible and does not require authentication.
Request Body
User’s email address
User’s password
Login Examples
Login Response
Response Fields
JWT token for authentication (valid for 24 hours by default)
User’s email address
User’s role:
STUDENT, ORGANIZER, or ADMINUser’s unique identifier (userID)
User’s first name
User’s last name
Using JWT Tokens
After obtaining a JWT token from login, include it in theAuthorization header for all protected endpoints.
Header Format
Bearer (note the space after “Bearer”).
Authentication Examples
JWT Token Details
Token Structure
JWT tokens follow the standard three-part structure:Token Claims
The payload contains the following claims:- sub (subject): User’s email address
- iat (issued at): Token creation timestamp (Unix time)
- exp (expiration): Token expiration timestamp (Unix time)
Token Expiration
- Default expiration: 24 hours (86400000 milliseconds)
- Configurable via
expirationIntproperty - Expired tokens will result in 401 Unauthorized responses
Token Security
- Tokens are signed using HMAC-SHA algorithm
- Secret key is configured via
secreteJwtStringproperty - Tokens are validated on every request to protected endpoints
Public vs Protected Endpoints
Public Endpoints (No Authentication Required)
POST /api/auth/register- User registrationPOST /api/auth/login- User loginGET /api/events/**- Public event viewing (guests can view events)GET /api/uploads/**- Public access to uploaded assetsGET /actuator/health- Health checkGET /actuator/info- API information
Protected Endpoints (Authentication Required)
All other endpoints require a valid JWT token in the Authorization header.Role-Based Access Control
Some endpoints require specific roles:Error Responses
401 Unauthorized
Returned when:- No token is provided
- Token is malformed
- Token signature is invalid
- Token has expired
403 Forbidden
Returned when:- Token is valid but user lacks required role
- User account is suspended or inactive
Best Practices
Store Tokens Securely
Store Tokens Securely
- Use
localStorageorsessionStoragefor web applications - Never store tokens in cookies without HttpOnly and Secure flags
- Use secure storage mechanisms for mobile apps
Handle Token Expiration
Handle Token Expiration
- Implement automatic token refresh or re-login flow
- Clear stored tokens on logout
- Handle 401 responses by redirecting to login
Use HTTPS in Production
Use HTTPS in Production
- Always use HTTPS to prevent token interception
- Never send tokens over unencrypted HTTP connections
Implement Logout
Implement Logout
- Clear stored tokens on client-side logout
- Consider implementing token revocation for enhanced security
Security Configuration
The API uses Spring Security with the following configuration:- CSRF Protection: Disabled (stateless JWT authentication)
- Session Management: Stateless (no server-side sessions)
- CORS: Enabled with configured origins
- Password Encoding: BCrypt hashing algorithm
Next Steps
API Overview
Learn about API conventions and response formats
Explore Endpoints
Browse available API endpoints