Guides
Authentication
Google OAuth 2.0 with a consent screen, code exchange, refresh, revocation and the headers of every Google Ads API call.
The Google Ads API and the Data Manager API use OAuth 2.0 for web applications. The user authorizes your application on Google's consent screen, you exchange the code for tokens and send the access token in Authorization: Bearer on every call.
Scopes
| Scope | Grants |
|---|---|
https://www.googleapis.com/auth/adwords | The whole Google Ads API |
https://www.googleapis.com/auth/datamanager | events:ingest and requestStatus:retrieve |
openid, email, profile | id_token and the fields of /v1/userinfo |
A token without the API's scope gets 403 PERMISSION_DENIED "Request had insufficient authentication scopes." with ErrorInfo.reason ACCESS_TOKEN_SCOPE_INSUFFICIENT.
1. Redirect to the consent screen
https://google-ads.mimicr.dev/o/oauth2/v2/auth ?client_id=<client_id> &redirect_uri=https://app.example.com/oauth/google/callback &response_type=code &scope=openid%20email%20https://www.googleapis.com/auth/adwords%20https://www.googleapis.com/auth/datamanager &access_type=offline &prompt=consent &include_granted_scopes=true &state=st-123
In Mimicr, the screen lists the sandbox's Google users and the requested scopes, all checked. Unchecking a scope simulates granular consent: the token's scope comes back narrower. login_hint preselects a user.
| Choice | Redirect |
|---|---|
| Allow | {redirect_uri}?state=st-123&code=4/0A…&scope=…&authuser=0&prompt=consent |
| Cancel | {redirect_uri}?error=access_denied&state=st-123 |
prompt=none without a previous authorization | {redirect_uri}?error=interaction_required&state=st-123 |
Errors in the request itself (unknown client, unauthorized redirect_uri, response_type other than code) are shown on the page and never redirected, as with Google. While the anyRedirectUri toggle is on (the default), any redirect_uri is accepted; turn it off and register the URIs with PUT /v1/google-ads/oauth to test redirect_uri_mismatch (see Sandbox control).
2. Exchange the code
The token endpoint is form-encoded:
curl --request POST \ --url https://google-ads.mimicr.dev/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'code=4/0A…' \ --data-urlencode 'client_id=<client_id>' \ --data-urlencode 'client_secret=<client_secret>' \ --data-urlencode 'redirect_uri=https://app.example.com/oauth/google/callback' \ --data-urlencode 'grant_type=authorization_code'
{
"access_token": "ya29.a0…",
"expires_in": 3599,
"refresh_token": "1//0…",
"scope": "openid email https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/datamanager",
"token_type": "Bearer",
"id_token": "eyJ…"
}- The code is valid for 10 minutes and can be used only once; after that,
400 invalid_grant. refresh_tokenonly comes withaccess_type=offlineand on a new authorization.id_tokencomes whenopenidwas granted. In Mimicr it is an RS256 JWT signed with a sandbox key, withiss,aud(the client_id),sub,email,email_verifiedandexp.- The access token lasts 3599 seconds on the sandbox clock.
3. Refresh the access token
curl --request POST \ --url https://google-ads.mimicr.dev/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'client_id=<client_id>' \ --data-urlencode 'client_secret=<client_secret>' \ --data-urlencode 'refresh_token=1//0…' \ --data-urlencode 'grant_type=refresh_token'
The response is the same, without refresh_token: keep the one you already have. A revoked refresh token answers 400 {"error":"invalid_grant","error_description":"Token has been expired or revoked."}.
| Case | HTTP | error |
|---|---|---|
| Bad, used or expired code | 400 | invalid_grant |
Wrong client_secret or unknown client_id | 401 | invalid_client |
redirect_uri different from the one used on the screen | 400 | redirect_uri_mismatch |
| Missing parameter | 400 | invalid_request |
Unsupported grant_type (service accounts, for example) | 400 | unsupported_grant_type |
4. Who the user is
curl --url https://google-ads.mimicr.dev/v1/userinfo \ --header 'Authorization: Bearer <token>'
{ "sub": "122343554391532054181", "email": "gestor@minha-org.mimicr.dev", "email_verified": true }name and picture come with the profile scope. See Get user info.
5. Revoke
curl --request POST \ --url https://google-ads.mimicr.dev/revoke \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'token=1//0…'
Answers 200 {}. Revoking the refresh token invalidates its access tokens. An unknown or already revoked token answers 400 invalid_token.
Google Ads API headers
| Header | When |
|---|---|
Authorization: Bearer <token> | Always |
login-customer-id: <10 digits> | When the target account is reached through a manager account: the MCC's id, without hyphens. Not sent on listAccessibleCustomers or geoTargetConstants:suggest |
developer-token | Optional and ignored (retired by Google on September 9, 2026) |
The Data Manager API only uses Authorization; the login account goes in the body (destinations[].loginAccount).
Authentication errors
Before the API runs, Google's front end answers in the google.rpc.Status envelope:
| Case | HTTP | ErrorInfo.reason |
|---|---|---|
No Authorization header | 401 UNAUTHENTICATED | CREDENTIALS_MISSING |
| Unknown or revoked token | 401 UNAUTHENTICATED | ACCESS_TOKEN_TYPE_UNSUPPORTED, plus authenticationError: OAUTH_TOKEN_INVALID or OAUTH_TOKEN_REVOKED in the Ads API |
| Expired token | 401 UNAUTHENTICATED | ACCESS_TOKEN_EXPIRED, plus authenticationError: OAUTH_TOKEN_EXPIRED |
| Missing scope | 403 PERMISSION_DENIED | ACCESS_TOKEN_SCOPE_INSUFFICIENT |
| API disabled in the project | 403 PERMISSION_DENIED | SERVICE_DISABLED, with metadata.activationUrl and a google.rpc.Help link |
Shortcut for agents and CI
In Mimicr, POST https://api.mimicr.dev/v1/google-ads/token issues the access and refresh tokens of a sandbox user without the consent screen ({"user": "gestor@…", "scopes": [...]}; default: openid, email, adwords and datamanager). Use it in automated tests; your application keeps using the flow above.
To test expiration and revocation: oauth.expire_access_tokens expires every access token now and oauth.revoke revokes a user's authorization. See Testing in the sandbox.