Overview
Authentication in the Cross-Media Measurement API follows a two-phase process:- Obtaining an ID Token - Get an ID token from the OpenID Provider
- Making Authenticated API Calls - Use the ID token in your API requests
Authentication Flow
The authentication flow consists of two main phases: obtaining an ID token from the OpenID Provider, and using that token to make authenticated API calls.Obtaining an ID Token
Follow these steps to obtain an ID token for API authentication:Call the Authenticate method
Initiate the authentication process by calling the
Authenticate API method.Receive authentication request URI
The API server performs the following:
- Generates a random
noncevalue - Creates a unique
stateidentifier - Persists these values in the database for later validation
- Builds an authentication request URI with these parameters
- Returns the URI in the
Authenticateresponse
Navigate to the authentication URI
Open the returned authentication request URI in a web browser. This redirects you to the OpenID Provider’s login page.
Log in with your credentials
Complete the login process with your user credentials at the OpenID Provider.
Receive authentication response
After successful login, the OpenID Provider returns an authentication response to your user agent (browser).
Making Authenticated API Calls
Once you have an ID token, use it to make authenticated API calls:Server validates the token
The API server performs the following validation:
- Reads the
statevalue from the ID token - Retrieves the corresponding
noncevalue from the database - Validates the ID token using the
noncevalue - Verifies the token signature and expiration
Security Considerations
Token Storage
Token Storage
- Store ID tokens securely in your application
- Never expose tokens in client-side code or logs
- Use secure storage mechanisms appropriate for your platform
Token Expiration
Token Expiration
- ID tokens have a limited lifetime
- Implement token refresh logic to handle expiration
- Always check token validity before making API calls
HTTPS Only
HTTPS Only
- Always use HTTPS for all API communications
- Never send ID tokens over unencrypted connections
Troubleshooting
401 Unauthorized Error
401 Unauthorized Error
Invalid Nonce Error
Invalid Nonce Error
If nonce validation fails:
- The token may have been tampered with
- The state/nonce pair may have expired in the database
- Re-initiate the authentication flow to obtain a new token
Next Steps
Certificates
Learn about X.509 certificates used for digital signatures
Measurement Consumer Setup
Set up your MeasurementConsumer account
