Overview
KeyBox uses JWT (JSON Web Tokens) for authenticating API requests. Protected endpoints require a valid JWT token in the Authorization header.Authentication Methods
KeyBox supports two authentication methods:- Email/Password Authentication - Standard signup and login
- Google OAuth - OAuth-based authentication with Google
Signup
Create a new user account.Endpoint
Request Body
User’s full name
User’s email address
Password (minimum 6 characters)
Password confirmation (must match password)
Response
Success message
The ID of the created user
Example Request
Example Response
Login
Authenticate and receive a JWT token.Endpoint
Request Body
User’s email address
User’s password
Response
Success message
JWT authentication token (expires in 30 minutes)
The user’s ID
The user’s role (e.g., “DEVELOPER”)
Example Request
Example Response
Using Authentication Tokens
Once you have a JWT token, include it in the Authorization header for protected endpoints:Example Authenticated Request
Token Expiration
When a token expires, you’ll receive a 401 Unauthorized response:Google OAuth
KeyBox also supports Google OAuth authentication. The OAuth routes are configured at the root level:- Initiate OAuth flow through your KeyBox instance
- User is redirected to Google for authentication
- Upon success, user is redirected back with authentication established
Users who sign up with Google OAuth cannot use password-based login and vice versa.
Error Responses
Missing Token
Invalid Token Format
Invalid Credentials
Google OAuth Account
Best Practices
Secure Storage
Store JWT tokens securely (e.g., httpOnly cookies, secure storage)
Token Refresh
Implement automatic token refresh before expiration
HTTPS Only
Always use HTTPS in production to protect tokens
Error Handling
Handle 401 errors gracefully and redirect to login