TDV Adapter for YouTube Analytics

Build 22.0.8462

Headless Machines

Using OAuth on a Headless Machine

The following sections show how to authenticate a headless server or another machine on which the adapter cannot open a browser. You can authenticate with a user account or with a service account.

User Accounts

To authenticate with a user account, you need to authenticate from another machine. Authentication is a two-step process.
  1. Instead of installing the adapter on another machine, you can follow the steps below to obtain the OAuthVerifier value. Or, you can install the adapter on another machine and transfer the OAuth authentication values, after you authenticate through the usual browser-based flow.
  2. You can then configure the adapter to automatically refresh the access token from the headless machine.
You can follow the headless OAuth authentication flow using the adapter's embedded OAuth credentials or using the OAuth credentials for your custom OAuth app.

Using the Embedded OAuth Credentials

Obtain a Verifier Code

Follow the steps below to authenticate from another machine and obtain the OAuthVerifier connection property:

  1. Click the following link to open the YouTube Analytics OAuth endpoint in your browser.
  2. Log in and grant permissions to the adapter. You are then redirected to the callback URL, which contains the verifier code.
  3. Save the value of the verifier code. You will set this in the OAuthVerifier connection property.

On the headless machine, set the following connection properties to obtain the OAuth authentication values.

  • OAuthVerifier: Set this to the verifier code.
  • InitiateOAuth: Set this to REFRESH.
  • OAuthSettingsLocation: Set this to persist the encrypted OAuth authentication values to the specified file.

After the OAuth settings file is generated, set the following properties to connect to data:

  • OAuthSettingsLocation: Set this to the file containing the encrypted OAuth authentication values. Make sure this file gives read and write permissions to the adapter to enable the automatic refreshing of the access token.
  • InitiateOAuth: Set this to REFRESH.
  • ChannelId: Set this to the Id of a YouTube channel. If not specified, data is returned for the authenticated user's channel.
  • ContentOwnerId: Set this to the Id of the content owner if you want to generate content owner reports.

Transfer OAuth Settings

Follow the steps below to install the adapter on another machine, authenticate, and then transfer the resulting OAuth values.

On a second machine, install the adapter and connect with the following properties set:

  • OAuthSettingsLocation: Set this to a writable text file.
  • InitiateOAuth: Set this to GETANDREFRESH.
Test the connection to authenticate in the browser. The resulting authentication values are written, encrypted, to the path specified by OAuthSettingsLocation. Once you have successfully tested the connection, copy the OAuth settings file to your headless machine.

On the headless machine, set the following connection properties to connect to data:

  • OAuthSettingsLocation: Set this to the path to your OAuth settings file. Make sure this file gives read and write permissions to the adapter to enable the automatic refreshing of the access token.
  • ChannelId: Set this to the Id of a YouTube channel. If not specified, data is returned for the authenticated user's channel.
  • ContentOwnerId: Set this to the Id of the content owner if you want to generate content owner reports.

Using the Credentials for a Custom OAuth App

Create a Custom OAuth App

Creating a custom OAuth app is optional in the headless OAuth flow; you can skip creating an app by connecting with the adapter's embedded OAuth credentials. You might want to create a custom OAuth app to change the information displayed when users log into YouTube Analytics to grant permissions to the adapter.

See Creating a Custom OAuth App for a procedure. You can then follow the procedures below to authenticate and connect to data.

Obtain a Verifier Code

Set the following properties on the headless machine:

  • InitiateOAuth: Set this to OFF.
  • OAuthClientId: Set this to the Client Id in your app settings.
  • OAuthClientSecret: Set this to the Client Secret in your app settings.

You can then follow the steps below to authenticate from another machine and obtain the OAuthVerifier connection property.

  1. Call the GetOAuthAuthorizationURL stored procedure with the CallbackURL input parameter set to the exact Redirect URI you specified in your app settings.
  2. Open the returned URL in a browser. Log in and grant permissions to the adapter. You are then redirected to the callback URL, which contains the verifier code.
  3. Save the value of the verifier code. You will set this in the OAuthVerifier connection property.

On the headless machine, set the following connection properties to obtain the OAuth authentication values:

  • OAuthClientId: Set this to the consumer key in your app settings.
  • OAuthClientSecret: Set this to the consumer secret in your app settings.
  • OAuthVerifier: Set this to the verifier code.
  • OAuthSettingsLocation: Set this to persist the encrypted OAuth authentication values to the specified file.
  • InitiateOAuth: Set this to REFRESH.

After the OAuth settings file is generated, set the following properties to connect to data:

  • OAuthClientId: Set this to the consumer key in your app settings.
  • OAuthClientSecret: Set this to the consumer secret in your app settings.
  • OAuthSettingsLocation: Set this to the file containing the encrypted OAuth authentication values. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
  • InitiateOAuth: Set this to REFRESH.
  • ChannelId: Set this to the Id of a YouTube channel. If not specified, data is returned for the authenticated user's channel.
  • ContentOwnerId: Set this to the Id of the content owner if you want to generate content owner reports.

Transfer OAuth Settings

Follow the steps below to install the adapter on another machine, authenticate, and then transfer the resulting OAuth values.

On a second machine, install the adapter and connect with the following properties set:

  • OAuthSettingsLocation: Set this to a writable text file.
  • InitiateOAuth: Set this to GETANDREFRESH.
  • OAuthClientId: Set this to the client Id assigned when you registered your app.
  • OAuthClientSecret: Set this to the client secret assigned when you registered your app.

Test the connection to authenticate. The resulting authentication values are written, encrypted, to the path specified by OAuthSettingsLocation. Once you have successfully tested the connection, copy the OAuth settings file to your headless machine. On the headless machine, set the following connection properties to connect to data:

  • InitiateOAuth: Set this to REFRESH.
  • OAuthClientId: Set this to the consumer key in your app settings.
  • OAuthClientSecret: Set this to the consumer secret in your app settings.
  • OAuthSettingsLocation: Set this to the path to your OAuth settings file. Make sure this file gives read and write permissions to the adapter to enable the automatic refreshing of the access token.
  • ChannelId: Set this to the Id of a YouTube channel. If not specified, data is returned for the authenticated user's channel.
  • ContentOwnerId: Set this to the Id of the content owner if you want to generate content owner reports.

Service Accounts

Service accounts have silent authentication, without user authentication in the browser. You can also use a service account to delegate enterprise-wide access scopes to the adapter.

You need to create an OAuth application in this flow. See Creating a Custom OAuth App to create and authorize an app. You can then connect to YouTube Analytics data that the service account has permission to access.

After setting the following connection properties, you are ready to connect:

  • InitiateOAuth: Set this to GETANDREFRESH.
  • OAuthClientId: Set this to the Client Id in your app settings.
  • OAuthClientSecret: Set this to the Client Secret in your app settings.
  • OAuthJWTCertType: Set this to "PEMKEY_FILE".
  • OAuthJWTCert: Set this to the path to the .pem file you generated.
  • OAuthJWTCertPassword: Set this to the password of the .pem file.
  • OAuthJWTCertSubject: Set this to "*" to pick the first certificate in the certificate store.
  • OAuthJWTSubject: Set this to your enterprise Id if your subject type is set to "enterprise" or your app user Id if your subject type is set to "user".
  • ChannelId: Set this to the Id of a YouTube channel. If not specified, data is returned for the authenticated user's channel.
  • ContentOwnerId: Set this to the Id of the content owner if you want to generate content owner reports.
When you connect the adapter completes the OAuth flow for a service account.
  1. Creates and signs the JWT with the claim set required by the adapter.
  2. Exchanges the JWT for the access token.
  3. Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
  4. Submits the JWT for a new access token when the token expires.

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462