[Prerequisite]
We use G Suite Business.
"Deploy as a Web Application" is configured below.
·Run the application as the next user: 自分I
·Users with access to applications: 組織All members of the organization
[Purpose]
When operating spreadsheets with permissions on your company's systems
Apart from the running user, I am considering doing this as a developer user.
のProcessing flow and events 】
1. Run GAS linked to spreadsheet (general user)
↓
2. Developer user (GAS) deployed as a web application
I would like to control the logic in this way.
on the web application side in UrlFetchApp.fetch when running the spreadsheet
When calling doGet, it flies to the authentication page and cannot be executed
The following events have occurred:
[Verification and Restriction]
Of course, you can run 2 from a browser already logged in with your Google account.
Also, due to security concerns, GDrive is open to the public within the organization.
You cannot select "everyone" as the scope of access.
】Answer I would like to ask br
To invoke the GAS deployed as a web application in UrlFetchApp.fetch
Could you tell me how to pass the authentication in advance?
The purpose is to separate the running and development users when running the GAS.
I would appreciate it if you could advise me if there are people who have implemented this in a different way.
I solved myself.
I tried various things like "API Key" and "OAuth 2.0 Client ID" from GCP credentials, but
Simple solution... (I thought I did it before posting)
I used ScriptApp.getOAuthToken() for headers and it passed.
var payload={
// omission
};
var param = {
'method': 'POST'
, 'headers': {'Authorization': "Bearer" + ScriptApp.getOAuthToken()}
, 'payload': payload
};
var response=UrlFetchApp.fetch('Web App URL',param);
© 2024 OneMinuteCode. All rights reserved.