Skip to main content

Get service account token

Gets authorization token by service account data

Function GetServiceAccountToken(Val Data, Val Scope, Val Expire = 3600) Export

ParameterCLI optionTypeRequiredDescription
Data--authArbitraryJSON authorization data as a file, collection or binary data
Scope--scopeArray Of StringScope or array of scopes
Expire--expNumberToken lifetime in seconds
Returns

Map Of KeyAndValue - serialized JSON response from Google

tip

List of available scopes: [developers.google.com](https:

developers.google.com/identity/protocols/oauth2/scopes)


1C:Enterprise/OneScript code example
Data = "https://hut.openintegrations.dev/secret_test_data/google_service.json"; // URL, binary Data, file or collection

Scope = New Array;
Scope.Add("https://www.googleapis.com/auth/calendar");
Scope.Add("https://www.googleapis.com/auth/drive");
Scope.Add("https://www.googleapis.com/auth/spreadsheets");

Result = OPI_GoogleCalendar.GetServiceAccountToken(Data, Scope);
# JSON data can also be passed as a path to a .json file

oint gcalendar GetServiceAccountToken \
--auth "{'type':'service_account','project_id':'openintegrations','private_key_id':'***','private_key':'***','client_email':'***','client_id':'***','auth_uri':'https://accounts.google.com/o/oauth2/auth','token_uri':'***','auth_provider_x509_cert_url':'https://www.googleapis.com/oauth2/v1/certs','client_x509_cert_url':'***','universe_domain':'googleapis.com'}" \
--scope "['https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/spreadsheets']"
Result
{
"access_token": "***",
"expires_in": 3599,
"token_type": "***"
}