Secure your own MCP server
Use onefold as the authorization server for an MCP server you run — register it as a protected resource, publish resource metadata, and verify audience-bound access tokens.
If you run your own MCP server, onefold can be its authorization server. Your users sign in with their onefold account, an MCP client receives an access token made for your server and nothing else, and your server verifies that token.
This uses the same mechanism as Protect your API: your MCP server is a protected resource. Read that guide for the token details. This page covers what is specific to MCP.
How the pieces fit
| Role | Who |
|---|---|
| Resource server | Your MCP server |
| Authorization server | onefold, at https://onefold.eitozx.com |
| Client | The AI client your user connects, such as Claude Code or VS Code |
- The client calls your server with no token. Your server answers
401and points at its resource metadata. - The client reads your metadata, finds onefold, and reads onefold's authorization server metadata.
- The client sends the user to onefold with a PKCE challenge and
resource=<your server's identifier>. - The user signs in and approves.
- The client receives an access token whose
audis your server, and calls your server with it. - Your server verifies the token.
Set it up
Register your server as a protected resource
On an application's OAuth2 tab, under Protected resources, register your server's
identifier: the URL clients connect to, for example https://mcp.example.com/mcp.
The identifier must be an https URL with no query string and no fragment, and it is compared
exactly. https://mcp.example.com/mcp and https://mcp.example.com/mcp/ are different
identifiers. Register the form your clients send.
Publish protected resource metadata
Serve a JSON document that names onefold as your authorization server (RFC 9728). For a
server at https://mcp.example.com/mcp, the document lives at
https://mcp.example.com/.well-known/oauth-protected-resource/mcp.
{
"resource": "https://mcp.example.com/mcp",
"authorization_servers": ["https://onefold.eitozx.com"],
"bearer_methods_supported": ["header"],
"scopes_supported": ["openid", "identity"]
}resource must equal the identifier you registered, character for character.
Challenge unauthenticated requests
When a request has no token, or a token you refuse, answer 401 with a WWW-Authenticate
header naming the metadata document:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource/mcp"This header is what starts the client's discovery.
Verify the token
The access token is a JWT signed by onefold. Verify the signature against
https://onefold.eitozx.com/.well-known/jwks.json, and check:
| Claim | Check |
|---|---|
iss | https://onefold.eitozx.com |
aud | Your server's identifier, exactly |
exp | In the future |
Then use sub as the user's ID and scope for what they granted.
Protect your API has the code.
Refuse a token whose aud is not your server. That check is what stops a token issued for
another server from being used at yours.
What the client needs from onefold
onefold publishes authorization server metadata at
https://onefold.eitozx.com/.well-known/oauth-authorization-server. A client learns the
endpoints from it, along with these facts:
| Fact | Value |
|---|---|
| PKCE | Required, S256 only |
| Resource indicators | Supported. The client must send resource. |
| Client ID Metadata Documents | Supported, and advertised as client_id_metadata_document_supported. A client can identify itself with an https URL as its client_id. |
| Dynamic client registration | Not supported |
A client signs in in one of two ways:
- By its metadata document. A published client such as Claude Code names the document it
publishes as its
client_idand your server's identifier as itsresource. Nothing needs registering for the client. The person is signed in to the application that owns your resource, under that application's sign-in rules, security policy and plan. The consent screen names your application, the client and the host that published the document, and it is shown on every authorization by a client, whatever your application's consent settings. Before it, a signed-out user meets your application's sign-in page, with your branding and the ways in you enabled, such as passwords, passkeys, your social providers and emailed sign-in links and codes. - By an application's client ID. Register an application in the developer portal and give the client its client ID.
A client that can only register dynamically cannot sign in through onefold.
Scopes
Tokens for your server carry the ordinary onefold scopes the client requested and the user
approved: openid, identity, profile. onefold has no way for you to define your own
scopes. Decide what a user may do with each of your tools in your server, from sub.
Revocation
A JWT stays valid until it expires, even if the user removes the client's access. Access tokens last 15 minutes at most. To act on revocation sooner, introspect the token. See Check revocation with introspection.
Security checklist
- Verify the signature,
iss,audandexpon every request. - Accept tokens in the
Authorizationheader only. - Do not accept a onefold token issued without your
resource. It is opaque and is not proof of anything to your server. - Do not pass the user's token on to another service. It is for your server.
- Serve everything over
https.