Skip to main content

Authentication

NexSpace supports three authentication methods. Choose based on your use case.

API Keys

API keys are the simplest way to authenticate. Each key has scopes that control what it can access.

Key Prefixes

Sandbox keys share the production database but only see is_sandbox rows, skip real notifications and outbound platform webhooks, and are omitted from usage analytics totals. See Sandbox (test API keys) for isolation rules, TTL, and scope limits.

Scopes

Scopes follow the pattern resource:action. Wildcard resource:* grants all actions on a resource.

Key Rotation

Rotate keys with zero downtime — the old key remains valid for 24 hours:

OAuth 2.1 + PKCE

For apps where users grant access through a browser flow.

Discovery

Dynamic Client Registration (RFC 7591)

Clients can self-register without operator intervention:

Authorization Flow

  1. Redirect user to /oauth/authorize with PKCE code_challenge (S256)
  2. User logs in and grants scopes
  3. Exchange code + code_verifier at /oauth/token
  4. Receive access_token + refresh_token

Device Code Flow (RFC 8628)

For CLI tools and environments without a browser.
The NexSpace CLI handles this automatically. nexspace login runs the device-code flow by default (opening your browser); pass --token nex_pat_… to store a personal access token instead:
Credentials are stored in your OS keychain (macOS Keychain, Linux Secret Service, Windows Credential Manager) when available, falling back to ~/.nexspace/config.json (mode 0600). The CLI refreshes the OAuth access token automatically as it nears expiry, rotating the stored refresh token.

Verify identity

GET /api/auth/me returns the identity a credential authenticates as. It accepts any supported credential — API key (nex_live_/nex_test_), personal access token (nex_pat_), OAuth 2.1 access token, or first-party session — so it’s the canonical “who am I” probe for SDKs, MCP clients, and the CLI (nexspace whoami).
A missing or revoked credential returns 401.

Token Introspection (RFC 7662)

Resource servers can check whether a token is active and inspect its metadata. The caller authenticates as the client that owns the token — public clients (PKCE: CLIs, SPAs) present client_id alone; confidential clients also present client_secret. Works for both access tokens (JWT) and refresh tokens.
An active token returns its metadata; an unknown, expired, revoked, or foreign-owned token returns { "active": false } (never an error):

Token Revocation (RFC 7009)

Revoke a token when a session ends or a credential is compromised. Revoking a refresh token invalidates it and its entire rotation chain; revoking an access token invalidates the associated refresh chain so it can’t be renewed (the stateless access JWT itself remains valid until its short 1-hour exp). Per RFC 7009 the response is always 200 with an empty body.
nexspace logout clears stored credentials locally (keychain + config file).

Rate Limits

Every API response includes rate-limit headers: Default: 60 requests/minute per API key. Configurable per key up to 6,000/min.

Error Responses

Authentication errors return structured JSON with recovery hints: