Auth APIs
Enopsy Auth Backend — generate a tenant token, verify it, fetch the current user, and log out.
API 1. Generate Token
This API gives a token for a tenant. Pass this token in later requests as the auth-token header, the Authorization header, or as a Bearer token to access other API data.
Endpoint
| Method | POST |
|---|---|
| URL | https://backend-auth.enopsy.com/api/auth/generate-token?session_domain=.enopsy.com |
| Auth | Header x-tenant-id only. |
Headers
x-tenant-id: 65f1a2b3c4d5e6f7a8b9c0d1
Content-Type: application/json
Payload
{
"username": "[email protected]",
"password": "secret",
"isTeam": true
}
| Field | Type | Required | Notes |
|---|---|---|---|
username | string | Yes | |
password | string | Yes | Plain password |
isTeam | boolean | No (default true) | true = employee (TeamMember). false = client (User). |
session_domain=.enopsy.com must be listed in ALLOWED_SESSION_DOMAINS. Do not send tenant in the body.
Response 200
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"tokenName": "auth_token",
"session": {
"payload": {
"id": "...",
"_id": "...",
"name": "...",
"email": "[email protected]",
"isTeam": true,
"tenant": { "tenant_id": "65f1a2b3c4d5e6f7a8b9c0d1" }
},
"domain": ".enopsy.com"
}
}
Use token on later APIs in the header as auth-token, Authorization, or Authorization: Bearer <token>.
Errors
| Status | When |
|---|---|
400 | Missing session_domain, username, or password |
401 | Email not found or wrong password |
403 | Invalid / missing x-tenant-id, or session domain not allowlisted |
500 | Unexpected server error |
API 2. Logout
This API logs out the tenant user and revokes this token for that tenant only. Other tenants' tokens stay valid. After logout, the same token cannot access other APIs.
Endpoint
| Method | POST or GET |
|---|---|
| URL | https://backend-auth.enopsy.com/api/auth/logout |
| Auth | Pass the token from API 1 in the header as auth-token, Authorization, or Bearer. |
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
You can also send the token as auth-token: <token>.
Payload
No body is required.
Response 200
{
"message": "Logged out successfully from all services.",
"login_url": "https://auth.example.com"
}
Errors
| Status | When |
|---|---|
400 | Token missing |
401 | Token invalid, expired, or already revoked |
API 3. Verify
This API checks that the tenant token is still valid. Use it after login to confirm the session before opening the dashboard.
Endpoint
| Method | GET |
|---|---|
| URL | https://backend-auth.enopsy.com/api/auth/verify |
| Auth | Pass the token from API 1 in the header as auth-token, Authorization, or Bearer. |
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
You can also send the token as auth-token: <token>.
Query
| Field | Type | Required | Notes |
|---|---|---|---|
module | string | No (default other) | Use crm when calling from the CRM app. |
Payload
No body is required.
Response 200
{
"message": "Authenticated",
"user": {
"id": "...",
"email": "[email protected]",
"isTeam": true,
"isAdmin": true,
"tenant": { "tenant_id": "65f1a2b3c4d5e6f7a8b9c0d1" }
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"login_url": "https://auth.example.com"
}
Errors
| Status | When |
|---|---|
401 | Token missing, invalid, expired, revoked, or session expired due to IP change |
403 | OTP / trusted-device check required (2FA) |
500 | Unexpected server error |
API 4. Me
This API returns the logged-in tenant user's profile and extra details. Use the same token from API 1.
Endpoint
| Method | GET |
|---|---|
| URL | https://backend-auth.enopsy.com/api/auth/me |
| Auth | Pass the token from API 1 in the header as auth-token, Authorization, or Bearer. |
Headers
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
You can also send the token as auth-token: <token>.
Payload
No body is required.
Response 200
{
"_id": "...",
"name": "...",
"email": "[email protected]",
"role": "...",
"permissions": [],
"userDetails": {},
"decoded": {
"id": "...",
"email": "[email protected]",
"isTeam": true,
"tenant": { "tenant_id": "65f1a2b3c4d5e6f7a8b9c0d1" }
}
}
Password is not returned. isTeam: true loads a TeamMember; isTeam: false loads a client User.
Errors
| Status | When |
|---|---|
401 | Token missing, invalid, expired, or revoked |
404 | User not found in this tenant |
500 | Unexpected server error |
