Skip to content

Authentication

Trove uses Clerk for authentication. All API requests must include a valid token.

Trove accepts two types of tokens, depending on how you integrate.

Use for: Direct API calls from your app.

Session JWTs (typ: JWT) are issued by Clerk’s frontend SDKs when a user signs in. They are short-lived (minutes) and automatically refreshed by the Clerk SDK.

Obtain them via Clerk’s SDK integration in your app, then send them with each API request.

Use for: MCP clients (Claude Desktop, Cursor).

OAuth access tokens (typ: at+jwt, per RFC 9068) are obtained automatically by MCP clients through the OAuth 2.1 flow with PKCE (Proof Key for Code Exchange).

Supported scopes: profile, email, offline_access.

You do not need to configure this manually. MCP clients handle the token exchange after you authenticate in the browser.

Include your token using one of these methods:

MethodFormatRecommended for
HeaderAuthorization: Bearer <token>API calls, MCP clients
Cookie__session=<token>Browser-based apps

The Authorization header is the recommended approach for all non-browser integrations.

MCP clients discover Trove’s auth configuration automatically using standard metadata endpoints.

Terminal window
curl https://api.ontrove.sh/.well-known/oauth-protected-resource
{
"resource": "https://api.ontrove.sh/mcp",
"authorization_servers": ["https://your-instance.clerk.accounts.dev"],
"scopes_supported": ["profile", "email", "offline_access"],
"bearer_methods_supported": ["header"]
}
Terminal window
curl https://api.ontrove.sh/.well-known/oauth-authorization-server

Returns Clerk’s OAuth metadata including the authorization endpoint, token endpoint, supported grant types, and PKCE configuration.

Unauthenticated requests return 401 with a WWW-Authenticate header:

WWW-Authenticate: Bearer resource_metadata="https://api.ontrove.sh/.well-known/oauth-protected-resource"

MCP clients use this header to discover the auth server and initiate the OAuth flow automatically.

Common error responses:

StatusMeaning
401 UnauthorizedMissing or invalid token
Token typeLifetimeRenewal
Session JWTShort-lived (minutes)Automatically refreshed by Clerk SDK
OAuth access tokenLonger-livedRefresh token via offline_access scope

For server-side apps using Clerk’s SDK:

import { createClerkClient } from '@clerk/backend';
const clerk = createClerkClient({ secretKey: 'sk_...' });
// For server-to-server: use Clerk API keys
// For user-facing apps: use Clerk's frontend SDKs

For user-facing apps, use Clerk’s frontend SDKs to handle sign-in and token management. The SDK provides the session JWT automatically with each request.

import { useAuth } from '@clerk/clerk-react';
function useTroveSearch() {
const { getToken } = useAuth();
return async function search(query: string) {
const token = await getToken();
const res = await fetch('https://api.ontrove.sh/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'query Search($q: String!) { search(query: $q) { results { document { title } snippet } } }',
variables: { q: query },
}),
});
return res.json();
};
}