I created a simple code to send email using a corporate email.
In code.js I have this code. Via http and without authenticating I can run the script without problems.
const doGet = request => {
GmailApp.sendEmail('XXXX.bot@wilsonsons.com.br', 'Alert' , 'Mensage XXXXXXX')
}
But I activated the function to run only by the domain users. I created an account just to run the script and send emails.
I authenticated the project and activated Oauth consent screen and created an Oatuh account. I put the two scoopes that appear in the google script's info tab. https://mail.google.com/ https://www.googleapis.com/auth/script.projects I access the website https://web.postman.co/ and use ouathV2 and I enter all the client ID, client secret information. I click on the option to get the access token and give the script permission to run under the new account. The account is in the domain and has access to the script. I have these settings in appscript.json
{
"timeZone": "America/Sao_Paulo",
"dependencies": {
"enabledAdvancedServices": [
{
"userSymbol": "Gmail",
"version": "v1",
"serviceId": "gmail"
}
]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"webapp": {
"executeAs": "USER_DEPLOYING",
"access": "DOMAIN"
},
"oauthScopes": [
"https://mail.google.com/",
"https://www.googleapis.com/auth/script.projects"
],
"executionApi": {
"access": "DOMAIN"
}
}
When I execute a get, the error appears.
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
I'm looking in the documentation on Oauth authentication. I can't where I can auterize this access. I think I have to add this access in my script but I can't find anything in the documentation. I've accessed GCP several times and recreated the Oauthv2 account, but it still doesn't work.