googleapis / google-auth-library-nodejs

🔑 Google Auth Library for Node.js
Apache License 2.0
1.67k stars 374 forks source link

delegate credential using google script or javascript #1831

Open bertranddelcroix opened 1 week ago

bertranddelcroix commented 1 week ago

I found a tutorial article in the site internet for a delegate credential .

Here, I don't know the language in PHP. Is there a way to convert from this language to google script (GAS) or javascript ? otherwise how to do it?

Here is the small function in php (?) below

/----

from googleapiclient import discovery from httplib2 import Http from oauth2client import file, client, tools from google.oauth2 import service_account

SCOPES = ['https://www.googleapis.com/auth/gmail.settings.basic'] SERVICE_ACCOUNT_FILE = 'the-downloaded-keyfile.json'

// # The user we want to "impersonate" USER_EMAIL = "someone@yourdomain.com"

credentials = service_account.Credentials.\ from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) delegated_credentials = credentials.with_subject(USER_EMAIL)

service = discovery.build('gmail', 'v1', credentials=delegated_credentials)

send_as_addresses = service.users().settings().sendAs().\ list(userId=USER_EMAIL, fields="sendAs(isPrimary,sendAsEmail)")

addresses = send_as_addresses.execute().get("sendAs", [])

/----

clundin25 commented 4 days ago

This sample code is Python (not PHP).

I'm going to route this to the Javascript repository so this can receive help from someone familiar with javascript.