Hardcoding json secrets file for service account authorization

257 views
Skip to first unread message

pe...@svensktkosttillskott.se

unread,
Jun 13, 2017, 3:55:55 AM6/13/17
to AdWords API Forum
Hi,

Is there a way to hardcode the json file into my application for authorization when creating a new AdwordsUser()? 

The only field I can find for the json file information is the OAuth2SecretsJsonPath. I do not wish to provide the file with a file name, I would much prefer to hardcode it as a variable.

In vb.net:
Private Shared ReadOnly _CLIENT_SECRETS_ADWORDSAPP_CONFIG As AdWordsAppConfig = New AdWordsAppConfig() With {
                .UserAgent = "MyAppName",
                .OAuth2Scope = "https://www.googleapis.com/auth/adwords",
                .OAuth2Mode = "SERVICE_ACCOUNT",
                .OAuth2PrnEmail = "MySupe...@GSuiteEnabledDomain.com",
                .OAuth2SecretsJsonPath = (""), ' --- want to replace this with hardcoded secret
                .EnableSoapExtension = True,
                .EnableGzipCompression = True,
                .IncludeUtilitiesInUserAgent = True
            }


Cheers

Ivan Bautista

unread,
Jun 13, 2017, 7:11:13 AM6/13/17
to AdWords API Forum
Hi Peter,

As per guide, if you are generating OAuth2 credentials via service account flow, the path to the generated .json file seems to be the only value that you can set for OAuth2SecretsJsonPath key in the config file. You may double check with the .NET client library team to confirm.

Alternatively, you may want to consider generating OAuth2 credentials using the installed application flow instead. It achieves similar goal and allows you to set client Id and client secret variables instead of setting a file path. 

Regards,
Ivan
AdWords API Team

pe...@svensktkosttillskott.se

unread,
Jun 13, 2017, 8:24:37 AM6/13/17
to AdWords API Forum
Thanks Ivan. Does installed application flow allow for 100% non user interaction. IE it will never ask for user intervention during authentication?

Ivan Bautista

unread,
Jun 14, 2017, 1:50:18 AM6/14/17
to AdWords API Forum
Hi Peter,

Basically, you just need to generate the OAuth2 credentials and refresh token once for the parent MCC account, then any of the child accounts under the MCC account can be accessed using the same OAuth2 credentials. You will just need to specify the clientCustomerId in the request header for the AdWords client account the user want to access data from. Here's a sample code for changing the clientCustomerId programmatically.

Another thing you need to look out for is when the access token expires, however, this is automatically handled by default if you use any of the available client libraries.

Let me know if this helps.

pe...@svensktkosttillskott.se

unread,
Jun 14, 2017, 7:13:44 AM6/14/17
to AdWords API Forum
Thanks Ivan. 

I tested hardcoding the OAuth2 credential and refresh token with the .net client library with great sucess. Very clean and the refresh seems robust. I marked your earlier responce as the completion of this thread.

Best Regards,
Peter Valenta
Reply all
Reply to author
Forward
0 new messages