Skip to main content

OAuth Authentication for Client API

OAuth is the recommended authentication method for per-user Client API integrations. You authenticate with an OAuth access token instead of managing a Glean-issued API token.

There are two sources for that token, and they behave slightly differently on the wire:

Glean OAuth Authorization Server

Glean issues the tokens (OAuth 2.1)

  • Authorization Code flow with PKCE
  • Two registration modes: Dynamic Client Registration (DCR), subject to tenant policy, and admin-created static clients
  • Glean-defined, fine-grained scopes
  • Recognized by issuer — no extra header
  • Powers the remote MCP server

External Identity Provider

Your IdP issues the tokens

  • Google, Okta, Azure Entra ID, OneLogin, etc.
  • Token lifecycle owned by your IdP
  • Requires the X-Glean-Auth-Type: OAUTH header
  • Reuses your existing enterprise auth
warning

This guide describes OAuth for the Client API. The Platform API supports the same customer-facing authentication methods through its Platform authentication guide. Indexing API operations require Glean-issued credentials and do not accept OAuth.


Authentication Headers

Every OAuth request sends the access token as a bearer credential:

Authorization: Bearer <oauth_access_token>

Whether you also need X-Glean-Auth-Type: OAUTH depends on who issued the token:

Token sourceX-Glean-Auth-Type: OAUTH
Glean OAuth Authorization Server (incl. Dynamic Client Registration)Not required — Glean recognizes its own tokens by their issuer
External identity provider (Google, Okta, Azure, etc.)Required — without it the token is treated as a Glean API token and rejected with 401
Using an SDK?

The official API clients accept an OAuth access token in their existing token field. See the OAuth section of the TypeScript, Python, Go, or Java client docs.


Setup

The Glean OAuth Authorization Server is an OAuth 2.1 authorization server that issues access tokens for the Client API. It reuses your existing SSO. It does not replace your IdP. It is on by default. Tenants that already used IdP OAuth may have it off.

1

Confirm the authorization server if sign-in fails

Start with OAuth. If sign-in fails, ask a Glean administrator to confirm that the Glean OAuth Authorization Server is enabled and that your client is allowed.

2

Choose a client-registration mode

Dynamic Client Registration (DCR) lets the client register itself. A tenant can allow any application that supports DCR, restrict registration to approved applications using the Glean-managed list, custom redirect URI patterns, or both, or disable DCR entirely. DCR clients receive only the restricted scope set configured for DCR. See Dynamic Client Registration.

A static OAuth client is an application an administrator registers and governs. Use a static client when DCR is disabled, when the tenant restricts DCR to approved applications and this application is not allowed, or when the application needs scopes DCR does not grant. See static OAuth clients.

3

Obtain a token

Use the Authorization Code flow with PKCE. Discover endpoints from the server metadata document and exchange the authorization code for an access token. For a static client, follow the static-client token example. For DCR, the host or application registers itself, then completes the same token flow.

Endpoints (replace <instance> — see finding your server URL):

PurposeURL
OAuth server metadatahttps://<instance>-be.glean.com/.well-known/oauth-authorization-server
Tokenhttps://<instance>-be.glean.com/oauth/token
Dynamic Client Registration (when advertised and allowed)https://<instance>-be.glean.com/oauth/register

The metadata document is the authoritative source for endpoints — fetch it to discover the current authorization, token, registration, and any other endpoints rather than relying on the values listed above. A registration endpoint does not mean every application, redirect URI, or scope is permitted to use DCR.

Tokens from the Glean Authorization Server are recognized by their issuer, so requests do not need the X-Glean-Auth-Type header.


Implementation Examples

The Glean Authorization Server example below shows a static-client token used with the Client API. To try the same authenticated endpoint interactively in your own tenant, use the Search API Explorer. API Explorer is for tenant testing only, not production sample code.

curl -X POST https://<instance>-be.glean.com/rest/api/v1/search \
-H 'Authorization: Bearer <oauth_token>' \
-H 'Content-Type: application/json' \
-d '{
"query": "quarterly reports",
"pageSize": 10
}'

Token Properties

  • Scope: Governed by Glean scopes (for example SEARCH, CHAT). For static clients, the allowed scopes are selected when the client is created or edited. Dynamically registered (DCR) clients receive only the restricted scope set configured for DCR, so use a static client when the scopes your application needs are not available through DCR. Request only the scopes your integration needs
  • User context: Treated as user-permissioned; permissions are enforced by Glean at request time
  • Expiration & refresh: Controlled by the issuer (Glean Authorization Server or your IdP). For a refresh token, request the offline_access scope and refresh with a standard OAuth library
  • API support: These setup instructions apply to Client API. For Platform API, see Platform API Authentication. Indexing API does not support OAuth

Troubleshooting OAuth

ErrorCauseSolution
401 Unauthorized / Invalid SecretExternal-IdP token sent without X-Glean-Auth-Type: OAUTH, so it was treated as a Glean API tokenAdd the X-Glean-Auth-Type: OAUTH header (external-IdP tokens only)
401 UnauthorizedInvalid or expired tokenVerify the token is valid and not expired; refresh if needed
403 ForbiddenOAuth not enabled, or client ID / issuer mismatchConfirm OAuth is enabled in Glean and the registered client ID / issuer matches the token
Invalid token formatMalformed tokenVerify the token is a valid JWT from your issuer
note

If you are using the Glean OAuth Authorization Server and still see a missing-header error, confirm the token was issued by Glean's server (not your IdP). Glean-issued tokens are detected by issuer and need no header; external-IdP tokens always do.


Best Practices

Security

  • Use HTTPS for all OAuth flows and API requests
  • Use Authorization Code + PKCE — it is required by OAuth 2.1 and by the Glean Authorization Server
  • Store tokens securely — never commit them to version control
  • Handle token refresh gracefully using a standard OAuth library

Production

  • Use production OAuth applications — don't ship development credentials
  • Reuse an access token until it expires rather than requesting a new one per call, and refresh once it expires
  • Monitor authentication failures through your issuer and Glean

Next Steps


Need Help?

  • Admin Setup: Contact your Glean administrator for OAuth configuration
  • Provider Issues: Consult your identity provider documentation
  • API Issues: Check the Client API Reference
  • Community: Join discussions at community.glean.com