OAuth

Discovery, registration, authorization, tokens and revocation.

MCP clients find everything on this page on their own. It is here for anyone building a client.

Endpoints

EndpointMethod and URL
Protected resource metadataGEThttps://ads.drefly.pro/.well-known/oauth-protected-resource/api/ads/mcp
Authorization server metadataGEThttps://ads.drefly.pro/.well-known/oauth-authorization-server
Client registrationPOSThttps://ads.drefly.pro/api/ads/oauth/register
AuthorizationGEThttps://ads.drefly.pro/api/ads/oauth/authorize
TokenPOSThttps://ads.drefly.pro/api/ads/oauth/token
RevocationPOSThttps://ads.drefly.pro/api/ads/oauth/revoke

Discovery

An MCP request without a token returns 401 with a WWW-Authenticate header that points to the protected resource metadata.

Response header
WWW-Authenticate: Bearer realm="drefly-ads", resource_metadata="https://ads.drefly.pro/.well-known/oauth-protected-resource/api/ads/mcp"

Register a client

Clients are public, so token_endpoint_auth_method is always none. Redirect addresses must be https, a loopback address such as http://127.0.0.1:PORT/callback (any port matches), or an app link such as cursor://. Up to 5 addresses per client.

Shell
curl -X POST https://ads.drefly.pro/api/ads/oauth/register \
  -H "Content-Type: application/json" \
  -d '{"client_name":"Nova ads bot","redirect_uris":["http://127.0.0.1:8765/callback"]}' 

Authorize

Send the owner to the authorization URL. PKCE with S256 is required. The resource parameter, when sent, must be the server URL. The owner approves on Drefly Ads, then returns to your redirect address with code, state and iss.

URL
https://ads.drefly.pro/api/ads/oauth/authorize?response_type=code
  &client_id=drc_...
  &redirect_uri=http%3A%2F%2F127.0.0.1%3A8765%2Fcallback
  &code_challenge=BASE64URL_SHA256_OF_VERIFIER
  &code_challenge_method=S256
  &scope=read%20write
  &state=random
  &resource=https%3A%2F%2Fads.drefly.pro%2Fapi%2Fads%2Fmcp

Exchange the code

Shell
curl -X POST https://ads.drefly.pro/api/ads/oauth/token \
  -d grant_type=authorization_code \
  -d code=CODE_FROM_REDIRECT \
  -d code_verifier=YOUR_VERIFIER \
  -d client_id=drc_... \
  -d redirect_uri=http://127.0.0.1:8765/callback
Response
{
  "access_token": "dro_...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "drr_...",
  "scope": "read write"
}

Refresh and revoke

Refresh tokens work once and are replaced on every refresh. Sending a used refresh token again revokes the connection. Revoking a refresh token disconnects the app.

Shell
curl -X POST https://ads.drefly.pro/api/ads/oauth/token \
  -d grant_type=refresh_token -d refresh_token=drr_... -d client_id=drc_...

curl -X POST https://ads.drefly.pro/api/ads/oauth/revoke \
  -d token=drr_... -d client_id=drc_...

Lifetimes

ItemLifetime
Connection page10 minutes, used once
Authorization code5 minutes, used once
Access token60 minutes
Refresh tokenUntil the connection expires, used once
Connection7, 30 or 90 days, chosen by the owner

Next steps

Was this page helpful?