Skip to main content
LinkXG supports two authentication methods: OAuth 2.0 for machine-to-machine integrations, and JWT tokens for user-context operations. This guide covers both.

Authentication methods

For most integrations, OAuth 2.0 is the recommended approach.
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.
  1. Go to Account > API Access
  2. Select Create OAuth Client
  3. Provide a name for the client (e.g., “ERP Integration”)
  4. Select the scopes you need
  5. Save the client
You will receive a 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:
Response:
The token expires in 900 seconds (15 minutes). Request a new token before it expires.

Step 3: Use the token

Include the token in the Authorization 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:
This invalidates the old secret and returns a new one. Update your integration before the old secret stops working.

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

Response:

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:
Refresh tokens are rotated on each use — you receive a new refresh token with each refresh request. The old refresh token is invalidated.

Logout

Invalidate your session:

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 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:
To prevent account enumeration, this endpoint always returns 200 with a fixed message, whether or not the address maps to an account:
The email contains a link whose single-use token is placed in the URL fragment (#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:
Redeem accepts two kinds of token. An existing-user sign-in token sets the session cookies and returns the signed-in user — it materialises a session for a user whose company already exists and does not create a company:
A passwordless sign-up intent token provisions the tenant and user at redeem and then signs them in, returning the same envelope. If the sign-up instead resolves to a domain that gates joins, redeem creates an inactive user plus a join request and returns 200 with no cookies:
An invalid, expired, or already-used token returns 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.
Step 2 — handle the callback. The provider redirects back to the callback endpoint with 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.
Both SSO endpoints respond with redirects (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