Authentication methods
For most integrations, OAuth 2.0 is the recommended approach.
OAuth 2.0 (recommended)
OAuth 2.0 Client Credentials flow is designed for machine-to-machine communication where no user interaction is required.Step 1: Create an OAuth client
OAuth clients are created in the LinkXG application by an Owner or Admin.- Go to Account > API Access
- Select Create OAuth Client
- Provide a name for the client (e.g., “ERP Integration”)
- Select the scopes you need
- Save the client
client_id and client_secret. Store the secret securely — it is shown only once.
Step 2: Request an access token
Exchange your credentials for an access token:Step 3: Use the token
Include the token in theAuthorization header of all API requests:
Available scopes
Request only the scopes you need. Tokens with broader scopes carry greater risk if compromised.
Rotating client secrets
If your client secret is compromised, rotate it immediately:JWT authentication (user context)
JWT authentication is used when actions need to be performed in the context of a specific user, typically for interactive applications.Login
Using the token
Include the access token in requests:Refreshing tokens
Access tokens expire after 15 minutes. Use the refresh token to obtain a new access token:Logout
Invalidate your session:Cookie sessions (/auth/v2)
The LinkXG web application signs in through a separate, browser-first authentication surface under /auth/v2. Instead of returning tokens in the response body, these endpoints set the access, refresh, and CSRF tokens as HttpOnly cookies scoped to .linkxg.com. This is the path that powers passwordless sign-in (magic links) and single sign-on (SSO). It is intended for first-party browser clients; server-to-server integrations should continue to use OAuth 2.0.
All /auth/v2 endpoints are public (no bearer token required) and enforce an Origin/Referer allowlist. On the JSON endpoints (login, refresh, logout, and the magic-link pair) a request that carries an Origin header which is not on the allowlist is rejected with 403; the SSO redirect endpoints fail the flow rather than returning JSON. State-changing requests authenticated by the session cookie must also carry the X-CSRF-Token header matching the linkxg_csrf cookie.
Cookies issued
POST /auth/v2/login (email + password), POST /auth/v2/refresh (rotates the session from the linkxg_refresh cookie; returns 204 with no body), and POST /auth/v2/logout (revokes the session and clears the cookies; idempotent, returns 204) round out the session lifecycle.
Magic-link sign-in
Magic links let a user sign in without a password. Request a link, then redeem the token it carries for a cookie session. Step 1 — request the link:200 with a fixed message, whether or not the address maps to an account:
#token=…), not the query string, so it never reaches server logs. The client reads the token from location.hash and submits it in the request body — it must not be forwarded from the URL search parameters.
Step 2 — redeem the token:
200 with no cookies:
400 INVALID_OR_EXPIRED with details withheld.
Single sign-on (SSO)
SSO uses the OIDC Authorization Code flow with PKCE against Microsoft Entra (microsoft) and Google (google).
Step 1 — start the flow. Redirect the browser to the start endpoint. It generates a PKCE verifier and challenge, stores single-use OIDC state in Redis (10-minute TTL), and 302-redirects to the identity provider. The optional returnTo query parameter (a path, validated server-side) controls where the user lands after sign-in.
code and state. The server validates the state, exchanges the code for tokens, verifies the claims, and resolves the user:
- a returning SSO user or a new tenant founder is issued a v2 cookie session and redirected to
returnTo; - an existing same-email account is sent through magic-link confirmation;
- a domain join that needs owner/admin approval creates a join request and no session is issued.
302) rather than JSON, so they are driven by the browser, not called directly by an integration.
Token handling best practices
Store tokens securely. Never store tokens in client-side code, localStorage, or version control. Use secure server-side storage or environment variables. Refresh proactively. Request a new token before the current one expires. A token that expires mid-request will fail. Handle 401 errors gracefully. If you receive a 401 Unauthorized response, your token may have expired. Refresh it and retry the request. Use the minimum necessary scope. Tokens with broader scopes carry greater risk. Request only what you need. Rotate secrets regularly. Even without a suspected compromise, rotating client secrets periodically reduces risk.Error responses
Authentication errors return standard HTTP status codes:
Example error response:
Next steps
API Reference
Browse the complete API documentation
Rate limits
Understand usage limits and quotas

