Guides
Getting started

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

ScopeGrants
https://www.googleapis.com/auth/adwordsThe whole Google Ads API
https://www.googleapis.com/auth/datamanagerevents:ingest and requestStatus:retrieve
openid, email, profileid_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.

text
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.

ChoiceRedirect
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:

bash
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'
json
{
  "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_token only comes with access_type=offline and on a new authorization.
  • id_token comes when openid was granted. In Mimicr it is an RS256 JWT signed with a sandbox key, with iss, aud (the client_id), sub, email, email_verified and exp.
  • The access token lasts 3599 seconds on the sandbox clock.

3. Refresh the access token

bash
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."}.

CaseHTTPerror
Bad, used or expired code400invalid_grant
Wrong client_secret or unknown client_id401invalid_client
redirect_uri different from the one used on the screen400redirect_uri_mismatch
Missing parameter400invalid_request
Unsupported grant_type (service accounts, for example)400unsupported_grant_type

4. Who the user is

bash
curl --url https://google-ads.mimicr.dev/v1/userinfo \
  --header 'Authorization: Bearer <token>'
json
{ "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

bash
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.

HeaderWhen
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-tokenOptional 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:

CaseHTTPErrorInfo.reason
No Authorization header401 UNAUTHENTICATEDCREDENTIALS_MISSING
Unknown or revoked token401 UNAUTHENTICATEDACCESS_TOKEN_TYPE_UNSUPPORTED, plus authenticationError: OAUTH_TOKEN_INVALID or OAUTH_TOKEN_REVOKED in the Ads API
Expired token401 UNAUTHENTICATEDACCESS_TOKEN_EXPIRED, plus authenticationError: OAUTH_TOKEN_EXPIRED
Missing scope403 PERMISSION_DENIEDACCESS_TOKEN_SCOPE_INSUFFICIENT
API disabled in the project403 PERMISSION_DENIEDSERVICE_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.