Authentication and permissions

API keys for automations, OAuth 2.1 for apps and AI assistants, and the permissions (scopes).

🇧🇷 Ler em português

Every call sends a credential in the header:

Authorization: Bearer <API key or OAuth token>

The credential always acts on behalf of a team user: history, logs and notifications are recorded for that user, together with the channel used (api_key or oauth).

Which one should I use?

API keyOAuth 2.1
Typical usen8n, scripts, server-to-server integrationsClaude, ChatGPT, Cursor, third-party apps
How to get itWeb app → Integrações → Gerar chave (Create key)The app opens the Media Ops sign-in screen and you approve
PermissionsOnly the ones ticked when it was createdEverything your role allows
Lifetime30, 90, 180 or 365 days (or no expiration)1-hour token, refreshed automatically by the app
RevocationIntegrações → Revoke (takes effect within 15 s)Integrações → Remove access (immediate)

OAuth is the safest option for apps and assistants

No long-lived secret is copied around, the user explicitly approves access and can remove it at any time. Use API keys only where there is no screen to sign in (automations).

API keys

  • Format: mops_ + 43 characters. The key is shown only once; the server stores only its SHA-256 hash.
  • Keep it in a secrets vault (n8n credentials, an environment variable, a secrets manager). Never put it in code, spreadsheets or messages.
  • A key cannot create or revoke other keys — that requires signing in to the web app.
  • If a key leaks, revoke it in Integrações and create a new one.
curl https://media.ops.infotrafego.com.br/api/v1/me \
  -H "Authorization: Bearer $MEDIA_OPS_API_KEY"

OAuth 2.1

The authorization server is Media Ops' Supabase Auth (authorization code + PKCE, dynamic client registration enabled). Compatible apps discover everything on their own from:

DocumentURL
Protected resource metadata (RFC 9728)/.well-known/oauth-protected-resource
Authorization server metadata (RFC 8414)/.well-known/oauth-authorization-server

A call without credentials gets 401 with WWW-Authenticate: Bearer resource_metadata="…", which is where discovery starts.

The flow, from the user's point of view:

  1. the app opens …/auth/v1/oauth/authorize;
  2. Media Ops asks the user to sign in (if needed) and shows the consent screen ("App quer acessar o Media Ops", i.e. "App wants to access Media Ops") with the permissions;
  3. once approved, the app receives the token and starts calling the API/MCP on the user's behalf.

Permissions (scopes)

ScopeAllows
clients:readRead clients, Business Managers, ad accounts and assets
clients:writeRegister clients and Business Managers, sync assets, enable/disable ad accounts and archive clients (archiving requires an administrator)
balances:readRead ad account balances
balances:writeRefresh balances
meta:readQuery Meta and Google Drive (audiences, interests, locations, lead forms, posts, campaigns, ad sets, folders)
campaigns:readRead executions, progress and logs
campaigns:writeCreate, extend and retry campaigns
audiences:readRead audience creation runs
audiences:writeCreate engagement audiences
templates:readRead targeting templates
templates:writeCreate, rename and delete targeting templates
admin:usersManage users (administrators only)

Permissions are always capped by the user's current role: if an administrator loses that role, their keys lose admin:users immediately. Calling something without the required scope returns 403 with code: "insufficient_scope" and required_scope.

On MCP, the assistant only sees the tools your permissions allow.


Did this page help you?