GhaylStackDocumentationv1.0.2
العربيةWebsite
Security and access

Security and access

Authentication and tokens

Use the actual token endpoints and understand tenant selection, refresh and application boundaries.

Select the tenant and application

The API uses bearer authentication configured by Identity. Sign-in is tenant-specific. An ordinary tenant user signs in to Dashboard, while a root administrator uses Admin. The token-issuance endpoint checks the existing X-FSH-App header: a request naming dashboard with tenant: root is rejected with 403.

This header is an integration identifier already present in the source. It is not a UI translation key or a secret. Use the clients' existing API integration rather than renaming the header in one place and breaking the other side.

Issue tokens with the defined contract

Send POST /api/v1/identity/token/issue with a tenant header and JSON containing email, password and optional twoFactorCode. The following is an illustrative HTTP request; supply your own development account and API host.

http
POST /api/v1/identity/token/issue HTTP/1.1
Host: localhost:<api-port>
tenant: acme
X-FSH-App: dashboard
Content-Type: application/json

{"email":"<development-user>","password":"<password>"}

The successful contract contains accessToken, refreshToken, accessTokenExpiresAt and refreshTokenExpiresAt. Subsequent protected requests use Authorization: Bearer <access-token>. The authenticated token's tenant claim takes precedence over a tenant header for ordinary users.

The handler audits sign-in, issues the token, stores refresh information and attempts to create a session record. Session-tracking failure is logged and does not itself fail a successful sign-in, so a token response alone is not proof that the session table is healthy.

Refresh without treating an access token as permanent

POST /api/v1/identity/token/refresh accepts refreshToken and an optional token field holding the access token. The handler validates the refresh token and session state. When an access token is supplied, it cross-checks its subject. A successful refresh rotates the refresh token and updates the session's stored fingerprint.

Replace the previous token pair with the returned pair according to the client's existing authentication flow. Avoid concurrent refresh logic that keeps reusing a stale refresh token. Distinguish an expired access token, an invalid refresh token and a revoked session when diagnosing a sign-out.

Configure the issuer correctly

JwtOptions defines Issuer, Audience, SigningKey, AccessTokenMinutes and RefreshTokenDays. The option defaults are 30 minutes and 7 days for token lifetimes. Startup validation requires nonempty issuer and audience and a signing key of at least 32 characters; placeholder keys containing replace-with are rejected.

Keep actual signing material in the host's secret configuration. All API instances intended to validate the same tokens need compatible issuer, audience and signing configuration. A deployment that changes them can invalidate existing sessions' access tokens.

Diagnose a failed sign-in

Identity configures a five-failure, 15-minute account lockout. Token issue and refresh use the named auth rate-limit policy, so repeated requests can also hit throttling. A user with enabled TOTP must provide its code. Tenant activity and subscription guards may reject a request before the expected business flow completes.

Test success, incorrect credentials, tenant mismatch, TOTP, refresh rotation and revoked-session refresh. Use sessions and two-factor authentication and authorization for the checks that follow sign-in.

Implementation references

View MarkdownBack to top

Search documentation

Use ↑ ↓ to move, Enter to open and Esc to close.