Overview
The planned OrgStack API will use JSON Web Tokens (JWT) for authentication. To access protected endpoints, you will need to include a valid JWT token in theAuthorization header of your requests.
JWT tokens have an expiration time. When your token expires, you’ll need to obtain a new one by logging in again.
Authentication flow
Follow these steps to authenticate and make authorized API requests:Obtain credentials
Ensure you have valid user credentials (username/email and password) for the OrgStack system.
Obtaining a JWT token
To obtain a JWT token, send a POST request to the login endpoint with your credentials.Endpoint
Request body
| Field | Type | Required | Description |
|---|---|---|---|
username | string | Yes | Your username or email address |
password | string | Yes | Your account password |
Example request
Success response
Status Code:200 OK
| Field | Type | Description |
|---|---|---|
token | string | The JWT token to use for authentication |
userId | string | The unique identifier of the authenticated user |
username | string | The username of the authenticated user |
expiresIn | integer | Token expiration time in seconds |
Error responses
Status Code:401 Unauthorized
400 Bad Request
Using JWT tokens
Once you have a JWT token, include it in theAuthorization header of your requests using the Bearer authentication scheme.
Header format
Example authenticated request
Token expiration
JWT tokens expire after a set period (typically 24 hours). When your token expires, API requests will return a401 Unauthorized response.
Handling expired tokens
When you receive a401 error due to an expired token:
- Request a new token by calling
/api/auth/loginagain - Update your stored token with the new one
- Retry the failed request with the new token
Implement automatic token refresh logic in your application to handle expiration gracefully without requiring user intervention.
Security best practices
Follow these security best practices when working with JWT tokens:Use HTTPS in production
Always use HTTPS to encrypt tokens in transit. The localhost URL shown in examples is for development only.
Store tokens securely
Store tokens in secure storage mechanisms appropriate for your platform (e.g., encrypted storage, secure cookies, environment variables).
Don't expose tokens
Never log tokens, commit them to version control, or expose them in client-side code.
Implement token refresh
Build automatic token refresh logic to handle expiration without user disruption.
Common authentication errors
| Status Code | Error | Solution |
|---|---|---|
401 | Invalid username or password | Verify your credentials are correct |
401 | Invalid or expired token | Request a new token by logging in again |
401 | Missing authorization header | Include the Authorization header with your token |
403 | Insufficient permissions | Your account lacks permission for this operation |
Next steps
Now that you understand authentication, you can:- Explore available API endpoints in the documentation
- Build your integration using authenticated requests
- Implement error handling for authentication failures