Developers
OAuth for apps
For apps that act for other brands and creators. Each person signs in to Yap Factory and approves what your app can do. OAuth 2.1 with PKCE, for public clients: no client secrets.
View as MarkdownBuilding for your own account only? An API key is simpler. MCP clients such as Claude and ChatGPT do all of this for you.
The flow
- Discover the authorization server from the metadata.
- Identify your app with a Client ID Metadata Document, or register it.
- Send the person to authorize with a PKCE challenge. They sign in and approve.
- Swap the code for tokens at the token endpoint.
- Call the API or the MCP server with the access token. Refresh it when it expires.
- Revoke when the person disconnects in your app.
Discovery
A call to the MCP server without a token gets 401 with WWW-Authenticate: Bearer resource_metadata="…", which points to the protected resource metadata (RFC 9728). That names the authorization server, whose metadata (RFC 8414) lists every endpoint below.
| What | URL |
|---|---|
| Protected resource metadata | https:/ (MCP) and https:/ (REST) |
| Authorization server metadata | https:/ (also at /) |
| Authorize | https:/ |
| Token | https:/ |
| Register (DCR) | https:/ |
| Revoke | https:/ |
curl https://yapfactory.com/.well-known/oauth-authorization-serverIdentify your app
Client ID Metadata Document (preferred)
Host a small JSON file on your own https domain and use its URL as your client_id. We fetch it when someone first connects, and again once a day. Nothing to register, and your name and logo stay up to date.
{
"client_id": "https://yourapp.com/oauth/client.json",
"client_name": "Your App",
"client_uri": "https://yourapp.com",
"logo_uri": "https://yourapp.com/logo.png",
"redirect_uris": [
"https://yourapp.com/oauth/callback"
],
"grant_types": [
"authorization_code",
"refresh_token"
],
"token_endpoint_auth_method": "none"
}client_idmust equal the file's URL exactly.- Serve it with status
200, no redirects, under 20 KB, and answer within 5 seconds. - Up to 20
redirect_uris.
Dynamic Client Registration
Or register once (RFC 7591) and keep the client_id you get back. Clients are always public: no secret is issued, and token_endpoint_auth_method is none.
curl -X POST https://yapfactory.com/oauth/register \
-H "Content-Type: application/json" \
-d '{
"client_name": "Your App",
"redirect_uris": ["https://yourapp.com/oauth/callback"],
"grant_types": ["authorization_code", "refresh_token"]
}'{
"client_id": "yfc_8fK2mQ9xLp3VtR7nYc1B4dWz",
"client_name": "Your App",
"redirect_uris": [
"https://yourapp.com/oauth/callback"
],
"grant_types": [
"authorization_code",
"refresh_token"
],
"response_types": [
"code"
],
"token_endpoint_auth_method": "none"
}Send 1 to 10 redirect URIs. Client ids from registration start with yfc_.
Redirect URIs
httpsanywhere.httponly on loopback (localhost,127.0.0.1,[::1]), for desktop apps and CLIs. Loopback redirects match on any port.- A native app's own scheme, such as
cursor://orvscode://. - Never a fragment, or a user name or password in the URL.
Authorize
Make a random code_verifier (43 to 128 characters), hash it with SHA-256 for the code_challenge, and send the person's browser here. Only S256 is accepted.
https://yapfactory.com/oauth/authorize
?response_type=code
&client_id=https%3A%2F%2Fyourapp.com%2Foauth%2Fclient.json
&redirect_uri=https%3A%2F%2Fyourapp.com%2Foauth%2Fcallback
&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
&code_challenge_method=S256
&scope=read%20write
&state=af0ifjsldkj
&resource=https%3A%2F%2Fyapfactory.com%2Fapi%2Fv1resource(RFC 8707) ishttps://yapfactory.com/api/v1orhttps://yapfactory.com/mcp. One token works for both.- The person signs in if they need to, sees your app's name, where it sends them back to, and what it asks for. They can untick the second line to give read-only access, so check the
scopeyou get back with the tokens. - The consent screen says the app can draft and publish campaigns, invite creators, answer invites, send messages and schedule posts to their TikTok and Instagram, and that it can never charge their card, pay a creator or cancel a deal.
- If the person says no, we redirect back with
error=access_deniedand yourstate. Anything wrong with the request itself (an unknownclient_id, aredirect_urithat isn't registered, a missing challenge) is shown to the person on our page, and we never redirect. - We redirect back with
code, yourstateandiss(RFC 9207). Check thatissis the issuer from the metadata. Codes last 10 minutes and work once.
Get tokens
Swap the code at the token endpoint, form-encoded (JSON works too). Send client_id; there's no secret.
curl -X POST https://yapfactory.com/oauth/token \
-d grant_type=authorization_code \
-d code=yfo_... \
-d redirect_uri=https://yourapp.com/oauth/callback \
-d client_id=https://yourapp.com/oauth/client.json \
-d code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk{
"access_token": "yfa_...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "yfr_...",
"scope": "read write"
}Send the access token as Authorization: Bearer yfa_... to the REST API or the MCP server.
Refresh
Access tokens last an hour. Refresh tokens last 30 days and rotate: each refresh returns a new pair, and the old refresh token stops working. Store the new one every time.
curl -X POST https://yapfactory.com/oauth/token \
-d grant_type=refresh_token \
-d refresh_token=yfr_... \
-d client_id=https://yourapp.com/oauth/client.json- A refresh keeps the scope the person approved, and the answer's
scopesays what that is. Asking for more returnsinvalid_scope: send the person through authorize again. - Using a code or a refresh token twice ends the connection. We take it as a sign someone else has a copy. The person connects again.
Revoke
When someone disconnects in your app, revoke (RFC 7009). Revoking any token of a connection ends the whole connection. The answer is always 200.
curl -X POST https://yapfactory.com/oauth/revoke -d token=yfr_...People can also see and disconnect every connection themselves in Settings → AI agents. After that your tokens return 401.
Errors and limits
The token, register and revoke endpoints answer errors the OAuth way, not with the API's envelope:
{
"error": "invalid_grant",
"error_description": "That code is invalid or has expired."
}| `error` | Status | When |
|---|---|---|
invalid_grant | 400 | The code or refresh token is wrong, expired, already used, or was issued to another client; the redirect_uri doesn't match; or the PKCE check failed. |
invalid_client | 401 | No client_id, one we don't know, or a metadata document we couldn't read. |
invalid_scope | 400 | A scope we don't have, or a refresh asking for more than was approved. |
invalid_target | 400 | A resource that isn't the API or the MCP server. |
unsupported_grant_type | 400 | Anything but authorization_code and refresh_token. |
invalid_client_metadata | 400 | Registration with a bad redirect URI or grant type. |
invalid_request | 400 | A missing or malformed parameter. |
temporarily_unavailable | 429 | Too many calls from one place. Wait a few minutes. |
Limits per caller: 60 authorize requests and 120 token requests every 10 minutes, 60 revokes every 10 minutes, and 30 registrations an hour. Register once and keep the client_id; don't register per person.
Scopes
Ask for the coarse scopes, which is what the consent screen shows, or one resource at a time.
| Scope | Allows |
|---|---|
read | Every operation that reads. |
write | Every operation that acts, and every read. Asking for write adds read. |
<resource>:read | Reads on one resource. |
<resource>:write | Acts on one resource, and reads it. |
Resources: account, deals, campaigns, creators, marketplace, posts. So the full list is read, write, account:read, account:write, deals:read, deals:write, campaigns:read, campaigns:write, creators:read, creators:write, marketplace:read, marketplace:write, posts:read, posts:write. A missing or empty scope means read write.
Each operation's page names the scope it needs. Without it you get 403 insufficient_scope, with the scope to ask for in meta.required.