Overview
ArcHive uses JWT (JSON Web Token) based authentication. The authentication flow involves:- Register or login to receive access and refresh tokens
- Include the access token in the
Authorizationheader for protected endpoints - Refresh the access token when it expires using the refresh token
- Logout to invalidate both tokens
Authentication Flow
Access Tokens
Access tokens are short-lived JWT tokens used to authenticate API requests. Include them in theAuthorization header:
Refresh Tokens
Refresh tokens are long-lived tokens used to obtain new access tokens without requiring the user to log in again.Register User
Create a new user account and receive authentication tokens.POST /api/auth/register
Request Body
Valid email address (converted to lowercase)
Password meeting security requirements:
- Minimum 8 characters
- Maximum 64 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
User’s first name (1-50 characters)
User’s last name (1-50 characters)
Response
Success message: “Registration successful!”
User information object
JWT access token for API authentication
JWT refresh token for obtaining new access tokens
Login
Authenticate with existing credentials to receive tokens.POST /api/auth/login
Request Body
Valid email address (converted to lowercase)
User’s password
Response
Success message: “Login successful!”
User information object
JWT access token for API authentication
JWT refresh token for obtaining new access tokens
Refresh Access Token
Obtain a new access token using a valid refresh token.POST /api/auth/refresh
Request Body
Valid refresh token obtained from login or registration
Response
Success message: “Token refreshed successfully!”
New JWT access token for API authentication
New JWT refresh token (token rotation for security)
Logout
Invalidate both access and refresh tokens to end the session.POST /api/auth/logout
Headers
Bearer token with the access token:
Bearer YOUR_ACCESS_TOKENRequest Body
Refresh token to invalidate
Response
Success message: “Logout successful.”
Security Features
Token Blacklisting
When a user logs out, both the access and refresh tokens are blacklisted to prevent reuse.Password Requirements
Passwords must meet the following security criteria:- Minimum 8 characters, maximum 64 characters
- At least one uppercase letter (A-Z)
- At least one lowercase letter (a-z)
- At least one number (0-9)
- At least one special character
Rate Limiting
Authentication endpoints are protected with rate limiting:- Registration & Login: Standard rate limiting
- Token Refresh: Strict rate limiting to prevent abuse
JWT Algorithm
Tokens are signed using the HS256 (HMAC with SHA-256) algorithm.Error Responses
Common authentication errors:Invalid Credentials
Token Expired
Validation Error
Best Practices
Store tokens securely
Store tokens securely
Never store tokens in localStorage or sessionStorage in web applications. Use secure, httpOnly cookies or memory storage with proper security measures.
Refresh tokens proactively
Refresh tokens proactively
Refresh access tokens before they expire to maintain a seamless user experience. Implement token refresh logic in your API client.
Handle token rotation
Handle token rotation
The API implements token rotation - each refresh request returns a new refresh token. Always update your stored refresh token after a successful refresh.
Logout on security events
Logout on security events
Call the logout endpoint when detecting suspicious activity, password changes, or security-related events.