Protect your API
Verify who is calling your own API using onefold — with userinfo, or with audience-bound JWT access tokens issued for a protected resource you register (RFC 8707).
When your frontend or another client calls your own API, the API has to establish who the user is. It must not trust a user ID sent by the client. onefold gives you two ways to do that.
| Look the token up | Audience-bound tokens | |
|---|---|---|
| Your API receives | An opaque access token | A signed JWT made for your API |
| Your API verifies it by | Calling onefold's userinfo endpoint | Checking the signature and claims itself |
| Network call per request | Yes | No |
| Setup | None | Register a protected resource |
| Sees revocation | Immediately | When the token expires, or by introspection |
Start with the first. Use the second when you want offline verification, or when the token must be usable at your API and nowhere else.
Look the token up
Have the client send the onefold access token to your API, and ask onefold who it belongs to:
curl https://onefold.eitozx.com/api/v1/userinfo/ \
-H "Authorization: Bearer ACCESS_TOKEN"200returns the user's claims. Usesubas the user's ID.401means the token is invalid, expired or revoked. Refuse the request.
Each call counts toward your application's per-minute request budget. Cache the result for a short time, keyed on the token, instead of calling on every request.
An ordinary access token is opaque. Your API cannot verify one locally.
Audience-bound tokens
Register your API as a protected resource. A client then asks for an access token for that
resource, and receives a signed JWT whose aud is your API. Your API verifies it without
calling onefold.
Register the resource
On the application's OAuth2 tab, under Protected resources, choose Register a
resource and enter a name and the API's identifier, for example https://api.example.com.
The identifier:
- is an absolute
httpsURL, - has no query string, no fragment and no credentials,
- can be registered once, by one application,
- is compared exactly.
https://api.example.com/v1andhttps://api.example.com/v1/are two different identifiers. Only a bare trailing slash on the host makes no difference:https://api.example.com/is the same ashttps://api.example.com.
An application can register up to 10 protected resources.
Request a token for it
Add resource to the authorization request, exactly as registered:
GET https://onefold.eitozx.com/o/authorize/
?response_type=code
&client_id=YOUR_CLIENT_ID
&resource=https://api.example.com
&…- Send exactly one
resource. - At the token endpoint, leave
resourceout or repeat the same value. A different value is refused withinvalid_target. - A refresh keeps the audience: tokens from a refresh are for the same resource.
The client and the API can belong to different applications. Any application can request a token for a registered resource.
Verify the token in your API
The access token is a JWT signed with RS256, with the header typ set to at+jwt. Verify the
signature with the key from https://onefold.eitozx.com/.well-known/jwks.json whose kid
matches, then check the claims.
| Claim | Check |
|---|---|
iss | Equals https://onefold.eitozx.com |
aud | Equals your API's identifier, as a single string |
exp | Is in the future |
sub | The user's ID, as a string |
scope | The granted scopes, separated by spaces |
client_id | The application the token was issued to |
jti | A unique ID for this token |
import { createRemoteJWKSet, jwtVerify } from "jose";
const jwks = createRemoteJWKSet(
new URL("https://onefold.eitozx.com/.well-known/jwks.json"),
);
export async function authenticate(request: Request) {
const token = request.headers.get("authorization")?.replace(/^Bearer /, "");
if (!token) throw new Error("missing token");
const { payload } = await jwtVerify(token, jwks, {
issuer: "https://onefold.eitozx.com",
audience: "https://api.example.com",
algorithms: ["RS256"],
});
return { userId: payload.sub, scopes: String(payload.scope).split(" ") };
}The token carries no email and no profile. Identify the user by sub.
An audience-bound token works only at its audience
onefold's own userinfo endpoints refuse an audience-bound token. A token issued for your API cannot be used to read the user's claims from onefold, and an ordinary token is not accepted as proof for your API. Request each for its purpose.
Check revocation with introspection
A signature check cannot tell that a token was revoked before it expired. When that matters, introspect the token:
curl -X POST https://onefold.eitozx.com/o/introspect/ \
-u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
-d token=ACCESS_TOKEN- Authenticate as the application that registered the resource. It must be a confidential client.
- An active token answers
{"active": true, …}withscope,client_id,sub,aud,iss,token_typeandexp. - Anything else answers
{"active": false}: a token that is expired, revoked or unknown, an ordinary token with no audience, or a token for a resource you do not own. The answer does not say which. - Each call counts toward your request budget.
Remove a resource
Removing a protected resource stops new tokens being issued for it. Tokens already issued keep working until they expire.
Check scopes in your API
Whichever method you use, the token says who the user is and which onefold scopes they granted. What that user may do in your product is your API's decision. onefold has no roles or permissions for your end users.
For an MCP server
An MCP server is an API with a discovery convention on top. See Secure your own MCP server.
Any OpenID Connect library
Configure a standard OpenID Connect client library to sign users in with onefold, with the settings to use and the options to turn off.
Go-live checklist
What to check before your onefold integration serves real users — applications per environment, redirect URIs, secrets, callback handling, webhooks, custom domains and social providers.