Ayush Synapse uses JWT (JSON Web Tokens) signed with the HS256 algorithm to authenticate requests to protected endpoints. The token is issued byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sagar-grv/ayush-synapse/llms.txt
Use this file to discover all available pages before exploring further.
POST /auth/login and must be included in the Authorization header of every subsequent protected request. In demo mode (DEMO_MODE=True), any caller can obtain a fully-permissioned token without providing real credentials — making it easy to explore the API without a registration flow. In a production deployment, the login endpoint should be integrated with ABHA (Ayushman Bharat Health Account) to validate actual user credentials before issuing a token.
Obtaining a Token
Send aPOST request to /auth/login with a JSON body containing a user_id and a role. In demo mode, both fields are accepted as-provided — no password or credential is required.
Receive the token in the response
A successful login returns a signed JWT and a summary of the permissions granted:
Using the Token
Pass the token in theAuthorization HTTP header using the Bearer scheme. The header must be present on every call to a protected endpoint.
Token Lifetime
Tokens issued by Ayush Synapse are valid for 24 hours from the moment of issuance. The JWT payload includes two standard time claims:| Claim | Meaning | Value |
|---|---|---|
iat | Issued-at time | datetime.datetime.utcnow() |
exp | Expiry time (token becomes invalid after this) | datetime.datetime.utcnow() + datetime.timedelta(hours=24) |
verify_token method returns {"valid": False, "error": "Token has expired"} and all protected endpoints respond with HTTP 401 Unauthorized. To regain access, call POST /auth/login again to obtain a fresh token.
Roles and Permissions
Therole field in the login request body determines which endpoints the token holder may access when require_role decorators are applied. The two supported roles are:
| Role | Access Level |
|---|---|
clinician | Access to all standard endpoints: code lookup, translation, FHIR resources, and bundle ingestion. |
admin | Full access — all clinician permissions, plus any endpoint decorated with @require_role("admin"). An admin token satisfies any role check, because the require_role decorator accepts admin as a universal bypass role. |
auth_service.py:
admin, the endpoint returns HTTP 403 Forbidden.
AuthService Internals
TheAuthService class (defined in app/services/auth_service.py) is the single source of truth for all token operations in Ayush Synapse. Developers extending the platform can import and use the service directly.
generate_token(user_id, role)
generate_token(user_id, role)
Issues a signed JWT for the given user ID and role. The payload contains
user_id, role, iat, and exp claims. The token is encoded with the HS256 algorithm using the JWT_SECRET_KEY environment variable.verify_token(token)
verify_token(token)
Decodes and validates a JWT string. Returns a dict with
valid: True and the decoded payload on success, or valid: False and an error string if the token is expired or malformed.require_auth decorator
require_auth decorator
A Flask route decorator that enforces the presence of a valid Bearer token in the Usage:
Authorization header. On success, it stores the decoded payload in Flask’s g.user context so downstream handlers can read the caller’s identity and role.require_role(role) decorator
require_role(role) decorator
A parameterised Flask route decorator that combines authentication and role-based authorisation in a single step. It verifies the token and checks that the caller’s role matches the required role (or is Usage:
admin).JWT_SECRET_KEY Environment Variable
TheAuthService reads its signing secret from the JWT_SECRET_KEY environment variable at startup:
Demo Mode
When
DEMO_MODE=True (the default), the POST /auth/login endpoint grants a fully-permissioned token to any user_id without performing credential validation. This is intentional for trial and evaluation purposes — no ABHA account or password is needed.To disable demo mode and enforce real credential checks, set DEMO_MODE=False in your .env file and implement credential validation logic in the /auth/login route handler in app.py before calling auth_service.generate_token().