The CDATA connections in Infoworks allows users to connect to various sources, one such is Google Analytics. Connecting to Google Analytics to fetch the data requires OAuth authentication. The auth mechanism should set in such a way that refresh of access token is done automatically. Please follow below steps for the same.
Instructions
Set the jdbc url as
jdbc:cdata:googleanalytics:InitiateOAuth=GETANDREFRESH;
Add the email id of the Google Analytics user as the username. You can find the list of users in the Account User Management section in Google Analytics. Set the password to * .
Obtain the Oauth2 credentials, client id and client secret, from this page. If there are no credentials in OAuth client id section, you can create one using "create credentials".
https://developers.google.com/identity/protocols/oauth2/openid-connect#getcredentials
We now need to obtain the OAuth refresh token. Paste the below URL in the your browser after replacing the client id with your client id
https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=90499999048-a2m7ef05dkkkk3ha6baaaa9aeml70.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/analytics.readonly&redirect_uri=https%3A//oauth2.example.com/code&access_type=offline&prompt=consent
This URL will be redirected to another URL of this fashion. Save the redirected URL and copy the string which is of the form code=xxxxxxxxxxxxxx till '&scope'
https://oauth2.example.com/code?code=4/0AY0e-r60va68YJXqM_3xkBKstAJe19_mvsnwqys1zLFPTvzFnconcda96-z2KZuSvp0g&scope=https://www.googleapis.com/auth/analytics.readonlyAt this point we have code (from step 4), clientid and client secret. Based on these values run the following curl request
curl --location --request POST 'https://oauth2.googleapis.com/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-raw 'code=4/0Axxxxxxxxxxxxxxxxxxxxxxxx&client_id=xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&client_secret=xxxxxxxxxxxxxxxxxxxxxxxx&redirect_uri=https%3A//oauth2.example.com/code&grant_type=authorization_code'
This request outputs the a refresh_token in the json response, which should be saved.We, now, have ClientId, Client Secret and Refresh Token. Set the following connection parameters in the source set up page.
OAuthClientId: your-client-id-from-step3
OAuthClientSecret: your-client-secret-from-step3
InitiateOAuth: GETANDREFRESH
OAuthRefreshToken: your-refresh-token-from-step5
Profile: your-profile-id-from-google-analytics-page
Please see the screenshot below.
NOTE: one can generate refresh token very easily here
https://developers.google.com/oauthplayground/
Application Infoworks versions: 4.2x