Skip to content
Authentication and session

Authentication and session

Related guides: Local login and MFA, OAuth tokens, Session and logout, and First access and password.

GET POST /auth/login

Authenticates the user with HTTP Basic and establishes the session through a cookie. Can require MFA.

Access: HTTP Basic. For a dedicated provider, the user follows the PROVIDER\USER format.

HeaderRequiredValue
AuthorizationYesBasic <base64-credentials>
CF-Turnstile-ResponseConditionalCloudflare Turnstile token. Required when validation is enabled in the environment. See Cloudflare Turnstile.

Responses

HTTPMeaningBody
200Login completed. The session is sent in Set-Cookie: __Host-dirl_session.LoginResponse
206An MFA step is required.MfaChallengeResponse
400Missing credential, or CF-Turnstile-Response header missing or invalid.—
401Credential not accepted.—
403Access denied or Turnstile token rejected (invalid, expired or already used).—
503The Turnstile token could not be validated with Cloudflare.—
POST /directlink/v2/auth/login HTTP/1.1
Host: api.example.com
Authorization: Basic <base64-credentials>
Accept: application/json

GET POST /auth/mfa and /auth/mfa/register

/auth/mfa validates the second factor (login status 1 and 2). /auth/mfa/register confirms the TOTP registration (status 3). See the flow in Complete MFA.

Access: secure link received in linkURL in the login 206 response. Use the full URL.

Send the code in the p field: in the form, with POST (recommended), or in the query string, with GET.

FieldRequiredDescription
pYes/auth/mfa: PIN (email or SMS) or TOTP code. /auth/mfa/register: TOTP code generated by the app with the secret received.

/auth/mfa responses

HTTPMeaningBody
200Second factor validated. The session is sent in Set-Cookie: __Host-dirl_session.LoginResponse
400Invalid or expired link, or missing p.—
403Invalid TOTP code, user locked or not found.—

/auth/mfa/register responses

HTTPMeaningBody
200TOTP registered. Does not establish a session: log in again.MfaRegisterResponse
400Invalid or expired link, or missing p.—
403Invalid TOTP code or failure to store the secret.—
POST <full-secure-link-path> HTTP/1.1
Host: api.example.com
Content-Type: application/x-www-form-urlencoded

p=<pin-or-totp-code>

POST /auth/token and /oauth2/token

Issue a Bearer access token. The two paths are equivalent.

Access: public; the credential goes in the form.

Body: application/x-www-form-urlencoded, according to the grant.

FieldPassword grantToken exchangeDescription
grant_typeYes: passwordYes: urn:ietf:params:oauth:grant-type:token-exchangeGrant type.
usernameYes—User.
passwordYes—Password.
subject_token_type—Yes: urn:ietf:params:oauth:token-type:jwtType of the source token. Only JWT is accepted.
subject_token—YesSource JWT.
provider—NoProvider that validates the JWT. Takes precedence over the X-STCPDIRECTLINK-JWT-ISSUER header.
HeaderRequiredDescription
X-STCPDIRECTLINK-JWT-ISSUERNoAlternative to the provider field in token exchange. Does not authenticate protected routes.

Responses

HTTPMeaningBody
200Token issued. Includes Cache-Control: no-store.TokenResponse
400Grant or source token not accepted.OAuthError
POST /directlink/v2/oauth2/token HTTP/1.1
Host: api.example.com
Content-Type: application/x-www-form-urlencoded
Accept: application/json

grant_type=password&username=<user>&password=<password>

GET /auth/firstaccess

Starts the first access. Returns the secure link in linkURL and sends the PIN to the user by email or SMS.

Access: public.

ParameterInRequiredDescription
uqueryYesUser.
CF-Turnstile-ResponseheaderConditionalCloudflare Turnstile token, required when validation is enabled.

Responses

HTTPMeaningBody
200Secure link in linkURL; PIN sent to the user.SecureLinkResponse
400CF-Turnstile-Response header missing or invalid.—
403Turnstile token rejected (invalid, expired or already used).—
503The Turnstile token could not be validated with Cloudflare.—

GET /auth/forget

Starts password recovery. Returns the secure link in linkURL and sends the PIN to the user by email or SMS. Parameters and responses are the same as for /auth/firstaccess.

POST /auth/change

Completes the first access or password recovery.

Access: secure link (linkURL) returned by /auth/firstaccess or /auth/forget. The k stays in the URL and carries the identification and validity parameters; do not build them manually.

Accepts only POST. Send p and z in the form body (application/x-www-form-urlencoded), never in the URL:

Field (form)RequiredDescription
pYesPIN or code required by the flow.
zYesNew password.

Responses

HTTPMeaningBody
200Password changed.OperationResponse
400Invalid data or link.—
403The password change was refused.—
405Method other than POST.—

GET POST /auth/logout

Ends the local session. When applicable, clears the session cookie.

Access: session (Bearer token or cookie).

Responses

HTTPMeaning
200Session ended.
401Credential not accepted.
POST /directlink/v2/auth/logout HTTP/1.1
Host: api.example.com
Authorization: Bearer <access_token>