The surfaces
The three strategies are for the ingestion of events. The Query API key and the MCP token are
separate. A Query API key works with every SDK strategy.
Turn on SERVER_SIDE or JWT
A workspace starts withNONE. SERVER_SIDE and JWT are locked for each workspace until
GrainQL support turns them on. The lock does not depend on the plan. While the lock is on, the
Client authentication settings page shows the current strategy, and nobody can change it.
To remove the lock, send an email to support@grainql.com with the name of the workspace. After
support removes the lock, an admin or an owner can select the strategy at
https://grainql.com/dashboard/settings/authentication.
NONE
NONE is the default strategy of Analytics Web. The SDK sends events and reads configurations
with the tenant alias and no credential:
NONE for a public website, a landing page, development, or an app without user login.
SERVER_SIDE
SERVER_SIDE sends a secret key with every request in the Authorization: Bearer <secret>
header. The server validates the secret before it processes the request. Use it in a Node.js
backend, a server-side API route, a serverless function, or any other environment that keeps a
secret out of the browser.
To get the secret key:
- Open Settings, then API keys, at
https://grainql.com/dashboard/settings/api-keys. - Click Create key. Select the Send events access. Then create the key.
- Copy the key and store it in an environment variable. The dashboard shows the key one time.
- Open Settings, then Client authentication, at
https://grainql.com/dashboard/settings/authentication. Select Server secret and save.
JWT
JWT is for a browser app that already has a user login. Before each request, the SDK calls
authProvider.getToken() and sends the result in the Authorization: Bearer <token> header.
getToken returns a string or a Promise<string>.
Configure the token check in Settings, Client authentication. Select Your own JWTs.
Then fill in the Token check card. GrainQL checks the signature, the issuer, and the audience
of every token.
Then pass an
authProvider to the SDK:
getToken is getAccessTokenSilently from @auth0/auth0-react. With NextAuth.js,
getToken returns session.accessToken from getSession(). login({ authToken }) also sets
the strategy to JWT at run time. Read Identify users.
The user ID must match the token
WithJWT, the user ID in an event must equal the sub claim of the token. The server rejects
an event with another user ID. This rule stops one user from sending events as another user.
One configuration for two environments
The strategy is a configuration value, so one code path can serve development and production:Query API key
The Query API reads events out of GrainQL. It needs an API key with the “Query API” permission. The key is separate from the SDK strategies and from the secret key. An admin or an owner creates the key:- Open Settings, then API keys, at
https://grainql.com/dashboard/settings/api-keys. - Click Create key.
- Enter a Name, for example
Query API key. - Under Access, select Query API.
- Under Expires, choose 30 days, 90 days, 1 year, or 2 years. Then create the key.
- Copy the key and store it in an environment variable. The dashboard shows the key one time.
X-API-Key header:
MCP server
An AI assistant authenticates with OAuth 2.1. The MCP client registers itself, you approve the scopes on a consent screen, and the client receives anmcpat_… access token. No secret is
copied by hand. Read MCP server.