Eden-MDBS uses JWT (JSON Web Token) based authentication with support for username/password login and token refresh mechanisms.
Authenticate a user and receive a JWT token.
POST /api/v1/auth/login
Authorization: Basic <base64(username:password)>
X-Org-Id: <organization_id>| Header | Description |
|---|---|
Authorization | Basic auth with base64-encoded credentials |
X-Org-Id | Organization identifier |
The Authorization header uses Base64-encoded credentials:
# Encode credentials
echo -n "admin:password" | base64
# Result: YWRtaW46cGFzc3dvcmQ=
# Use in header
Authorization: Basic YWRtaW46cGFzc3dvcmQ=curl http://{host}:8000/api/v1/auth/login \
-u admin:password \
-H "X-Org-Id: TestOrg" \
-X POSTOr with explicit Basic auth header:
curl http://{host}:8000/api/v1/auth/login \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \
-H "X-Org-Id: TestOrg" \
-X POST{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW4iLCJ1c2VyX3V1aWQiOiI1NTBlODQwMC1lMjliLTQxZDQtYTcxNi00NDY2NTU0NDAwMDAiLCJvcmdfaWQiOiJteV9jb21wYW55Iiwib3JnX3V1aWQiOiI1NTBlODQwMC1lMjliLTQxZDQtYTcxNi00NDY2NTU0NDAwMDEiLCJleHAiOjE3MDU0OTI4MDAsImlhdCI6MTcwNTQwNjQwMH0.signature"
}Include the JWT token in the Authorization header for all authenticated API requests:
curl http://{host}:8000/api/v1/endpoints \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json"Refresh your JWT token before it expires to maintain session continuity.
POST /api/v1/auth/refresh
Authorization: Bearer <current_jwt_token>curl http://{host}:8000/api/v1/auth/refresh \
-H "Authorization: Bearer $TOKEN" \
-X POST{
"status": "success",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...new_token..."
}
}Token refresh also supports GET requests:
curl http://{host}:8000/api/v1/auth/refresh \
-H "Authorization: Bearer $TOKEN"Eden JWT tokens contain these claims:
{
"user_id": "admin",
"user_uuid": "550e8400-e29b-41d4-a716-446655440000",
"org_id": "my_company",
"org_uuid": "550e8400-e29b-41d4-a716-446655440001",
"exp": 1705492800,
"iat": 1705406400
}| Claim | Description |
|---|---|
user_id | String identifier for the user |
user_uuid | UUID identifier for the user |
org_id | String identifier for the organization |
org_uuid | UUID identifier for the organization |
exp | Token expiration timestamp (Unix epoch) |
iat | Token issued at timestamp (Unix epoch) |
Eden supports two methods for user identification:
Use email addresses or custom user identifiers:
Username: john.doe@company.com
Password: mypassword123Use UUID format for user identification:
Username: 550e8400-e29b-41d4-a716-446655440000
Password: mypassword123The system automatically detects the format:
{
"error": "Bad Request",
"message": "password not provided"
}{
"error": "Unauthorized",
"message": "Invalid credentials"
}{
"error": "Not Found",
"message": "User not found in organization"
}{
"error": "Unauthorized",
"message": "Token has expired"
}{
"error": "Unauthorized",
"message": "Invalid token format"
}You can validate tokens client-side before making API calls:
function isTokenValid(token) {
try {
const payload = JSON.parse(atob(token.split(".")[1]));
const now = Math.floor(Date.now() / 1000);
return payload.exp > now;
} catch {
return false;
}
}
function getTokenExpiry(token) {
try {
const payload = JSON.parse(atob(token.split(".")[1]));
return new Date(payload.exp * 1000);
} catch {
return null;
}
}sessionStorage or secure httpOnly cookieslocalStorage for sensitive applicationsRefresh tokens proactively before expiration:
// Refresh 5 minutes before expiry
const expiry = getTokenExpiry(token);
const refreshTime = expiry.getTime() - Date.now() - 5 * 60 * 1000;
if (refreshTime > 0) {
setTimeout(async () => {
const newToken = await refreshToken();
}, refreshTime);
}Handle authentication errors gracefully:
async function apiCall(endpoint) {
const response = await fetch(endpoint, {
headers: { Authorization: `Bearer ${token}` },
});
if (response.status === 401) {
// Try to refresh token
try {
await refreshToken();
return apiCall(endpoint); // Retry
} catch {
// Refresh failed, redirect to login
logout();
}
}
return response;
}