Establishing a Connection
Connecting to Google Cloud Storage
Provide the following connection property before setting the authentication properties.
- ProjectId: The Id of the project you want to connect to.
Authenticating to Google Cloud Storage
The provider supports using user accounts, service accounts and GCP instance accounts for authentication.
The following sections discuss the available authentication schemes for Google Cloud Storage:
- User Accounts (OAuth)
- Service Accounts (OAuthJWT)
- GCP Instance Accounts
User Accounts (OAuth)
AuthScheme must be set to OAuth in all user account flows.
Desktop Applications
CData provides an embedded OAuth application that simplifies OAuth desktop Authentication. Alternatively, you can create a custom OAuth application. See Creating a Custom OAuth App for information about creating custom applications and reasons for doing so.
For authentication, the only difference between the two methods is that you must set two additional connection properties when using custom OAuth applications.
After setting the following connection properties, you are ready to connect:
- InitiateOAuth: GETANDREFRESH. This instructs the provider to automatically attempt to get and refresh the OAuth access token.
- OAuthClientId (custom applications only): The client Id in your custom OAuth application settings.
- OAuthClientSecret (custom applications only): The client secret in the custom OAuth application settings.
- Extracts the access token from the callback URL.
- Obtains a new access token when the old one expires.
- Saves OAuth values in OAuthSettingsLocation that persist across connections.
Web Applications
When connecting via a web application, you must create and register a custom OAuth application with Google Cloud Storage. You can then use the provider to acquire and manage the OAuth token values. See Creating a Custom OAuth App for more information about custom applications.Get an OAuth Access Token
Set the following connection properties to obtain the OAuthAccessToken:
- OAuthClientId: The client Id in your application settings.
- OAuthClientSecret: The client secret in your application settings.
Then call the following stored procedures to complete the OAuth exchange:
- Call the GetOAuthAuthorizationURL stored procedure. Set the CallbackURL input to the callback URL you specified in your application settings. The stored procedure returns the URL to the OAuth endpoint.
- Navigate to the URL that the stored procedure returned in Step 1. Log in to the custom OAuth application and authorize the web application. Once authenticated, the browser redirects you to the callback URL.
- Call the GetOAuthAccessToken stored procedure. Set AuthMode to WEB and the Verifier input to the "code" parameter in the query string of the callback URL.
Once you have obtained the access and refresh tokens, you can connect to data and refresh the OAuth access token either automatically or manually.
Automatic Refresh of the OAuth Access Token
To have the provider automatically refresh the OAuth access token, set the following on the first data connection:
- InitiateOAuth: REFRESH.
- OAuthClientId: The client Id in your application settings.
- OAuthClientSecret: The client secret in your application settings.
- OAuthAccessToken: The access token returned by GetOAuthAccessToken.
- OAuthRefreshToken: The refresh token returned by GetOAuthAccessToken.
- OAuthSettingsLocation: The location where the provider saves the OAuth token values, which persist across connections.
Manual Refresh of the OAuth Access Token
The only value needed to manually refresh the OAuth access token when connecting to data is the OAuth refresh token.
Use the RefreshOAuthAccessToken stored procedure to manually refresh the OAuthAccessToken after the ExpiresIn parameter value returned by GetOAuthAccessToken has elapsed, then set the following connection properties:
- OAuthClientId: The client Id in your application settings.
- OAuthClientSecret: The client secret in your application settings.
Then call RefreshOAuthAccessToken with OAuthRefreshToken set to the OAuth refresh token returned by GetOAuthAccessToken. After the new tokens have been retrieved, open a new connection by setting the OAuthAccessToken property to the value returned by RefreshOAuthAccessToken.
Finally, store the OAuth refresh token so that you can use it to manually refresh the OAuth access token after it has expired.
Headless Machines
To configure the provider to use OAuth with a user account on a headless machine, you must authenticate on another device that has an internet browser.
- Choose one of two options:
- Option 1: Obtain the OAuthVerifier value as described in "Obtain and Exchange a Verifier Code" below.
- Option 2: Install the provider on a machine with an internet browser and transfer the OAuth authentication values after you authenticate through the usual browser-based flow, as described in "Transfer OAuth Settings" below.
- Then configure the provider to automatically refresh the access token on the headless machine.
Option 1: Obtain and Exchange a Verifier Code
To obtain a verifier code, you must authenticate at the OAuth authorization URL.
Follow the steps below to authenticate from the machine with an internet browser and obtain the OAuthVerifier connection property.
- Choose one of these options:
- If you are using the Embedded OAuth Application click Google Cloud Storage OAuth endpoint to open the endpoint in your browser.
- If you are using a custom OAuth application, create the Authorization URL by setting the following properties:
- InitiateOAuth: OFF.
- OAuthClientId: The client Id assigned when you registered your application.
- OAuthClientSecret: The client secret assigned when you registered your application.
- Log in and grant permissions to the provider. You are then redirected to the callback URL, which contains the verifier code.
- Save the value of the verifier code. Later you will set this in the OAuthVerifier connection property.
On the headless machine, set the following connection properties to obtain the OAuth authentication values:
- InitiateOAuth: REFRESH.
- OAuthVerifier: The verifier code.
- OAuthClientId (custom applications only): The client Id in your custom OAuth application settings.
- OAuthClientSecret (custom applications only): The client secret in the custom OAuth application settings.
- OAuthSettingsLocation: Set this to persist the encrypted OAuth authentication values to the specified location.
After the OAuth settings file is generated, you must re-set the following properties to connect:
- InitiateOAuth: REFRESH.
- OAuthClientId (custom applications only): The client Id assigned when you registered your application.
- OAuthClientSecret (custom applications only): The client secret assigned when you registered your application.
- OAuthSettingsLocation: The location containing the encrypted OAuth authentication values. Make sure this location gives read and write permissions to the provider to enable the automatic refreshing of the access token.
Option 2: Transfer OAuth Settings
Prior to connecting on a headless machine, you must create and install a connection with the provider on a device that supports an internet browser. Set the connection properties as described in "Desktop Applications" above.
After completing the instructions in "Desktop Applications", the resulting authentication values are encrypted and written to the location specified by OAuthSettingsLocation. The default filename is OAuthSettings.txt.
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: REFRESH.
- OAuthClientId (custom applications only): The client Id assigned when you registered your application.
- OAuthClientSecret (custom applications only): The client secret assigned when you registered your application.
- OAuthSettingsLocation: The location of your OAuth settings file. Make sure this location gives read and write permissions to the provider to enable the automatic refreshing of the access token.
Service Accounts (OAuthJWT)
To authenticate using a service account, you must create a new service account and have a copy of the accounts certificate. If you do not already have a service account, you can create one by following the procedure in Creating a Custom OAuth App.
For a JSON file, set these properties:
- AuthScheme: OAuthJWT.
- InitiateOAuth: GETANDREFRESH.
- OAuthJWTCertType: GOOGLEJSON.
- OAuthJWTCert: The path to the .json file provided by Google.
- OAuthJWTSubject (optional): Only set this value if the service account is part of a GSuite domain and you want to enable delegation. The value of this property should be the email address of the user whose data you want to access.
For a PFX file, set these properties instead:
- AuthScheme: OAuthJWT.
- InitiateOAuth: GETANDREFRESH.
- OAuthJWTCertType: PFXFILE.
- OAuthJWTCert: The path to the .pfx file provided by Google.
- OAuthJWTCertPassword (optional): The .pfx file password. In most cases you must provide this since Google encrypts PFX certificates.
- OAuthJWTCertSubject (optional): Set this only if you are using a OAuthJWTCertType, which stores multiple certificates. This should not be set for PFX certificates generated by Google.
- OAuthJWTIssuer: The email address of the service account. This address usually includes the domain iam.gserviceaccount.com.
- OAuthJWTSubject (optional): Only set this value if the service account is part of a GSuite domain and you want to enable delegation. The value of this property should be the email address of the user whose data you want to access.
GCP Instance Accounts
When running on a GCP virtual machine, the provider can authenticate using a service account tied to the virtual machine. To use this mode, set AuthScheme to GCPInstanceAccount.