Skip to main content
Kontext uses OAuth2 for all authentication. There are two flows for two different contexts, and two SDK surfaces that map to them.

Which flow do I need?

Most applications use both the Client SDK (for the user-facing auth flow) and the Server SDK (for credential exchange inside tool handlers).

How Kontext relates to your IdP

Kontext does not replace your identity provider for humans. Your users keep signing in through Okta, Google, Azure AD, or whatever IdP you use today.
Kontext is the identity provider for applications. It issues each application a verifiable identity (Client ID), manages the OAuth consent flow between users and applications, and brokers credentials from integrations at runtime.

Applications: Authorization Code + PKCE

When your application needs to act on behalf of a user, it uses the standard OAuth2 authorization code flow with PKCE.

Step 1: Redirect to authorization

The user sees what permissions are being requested and approves. One approval per session.

Step 3: Exchange code for tokens

Response:

Step 4: Use access token

Use the access token to call MCP tools via POST /mcp, or pass it to kontext.require() on your server to exchange it for integration credentials. The Client SDK handles this entire flow automatically. See the Client SDK for details.

Refreshing tokens

Server-side credential exchange

Once your application has a user’s access token (from the PKCE flow above), your server exchanges it for integration-specific credentials using kontext.require():
This is not a third OAuth flow. It’s a credential exchange. Kontext validates the user’s token, checks policy, and returns a short-lived credential from the user’s existing connection to that integration. Confidential servers can also exchange against an external end-user subject when they already know that stable ID:
In that mode, Kontext validates the configured external identity mapping and returns the same short-lived integration credential shape. See Server SDK: Credentials for the full API.

Service accounts: Client Credentials

Service accounts authenticate using OAuth2 client credentials. This is a machine-to-machine flow with no user interaction. Use this flow when your backend needs to manage infrastructure: create applications, configure integrations, set policies.
Response:
Use this token for Management API requests (/api/v1/*). Service accounts cannot invoke tools or access integration credentials. They are for infrastructure management only.

What’s next

Quickstart

See these flows in action with a working example

Server SDK: Credentials

Exchange user tokens for integration credentials

Client SDK

Handle auth flows, tool execution, and storage

Errors

Handle auth errors, connection errors, and policy denials