0
votes

I need to access a Google Apps Script in AJAX that needs authorization from the user to send an email from his GMail Account. For various reasons, I have to send that email from the Google Apps Script.

The call is made from my web application hosted on my server. I am also using Google Signin+ Authentication. I tried to include gmail in the my web app authorization scopes, but it is not sufficient because my web App and my Google Apps Script are not the same entity for Google (not the same client_id).

I would like the whole thing to work as following :

  1. The user authenticates on my web App on his Google Account
  2. He clicks on a button to send an email
  3. If he never gave the authorization to my Google Apps Script, the authorization popup is displayed
  4. He grants permissions, he is not redirected to the Google Apps Script result page, but stays on my web app
  5. The Google Apps Script sends the email, and returns something in JSONP to my Web App.

Is it possible to do that ?

I have thought of several solutions but I don't know how to make them work :

  1. Is there a way to set the Google Apps Script' s client_id to be the same as my Web App ?
  2. Or is there a way to create (& customize) the button which is automatically generated when I try to access a Google Apps Script to which I have not granted access, and display that button on my web app ?

I am stuck with this, any help much appreciated !

1

1 Answers

1
votes

None of your options are possible. You cant bypass that authorization screen in any way.
Using the same clientid or scopes wont help you, at most that would authorize your account not the users account. Each user is an independent oauth flow with its own token saved by apps script.
However
If you must, its now possible to do it in a different way because:
1) apps script now supports (since feb 2014) implementing your own oauth2 flow.
See StateTokenBuilder/ScriptApp.getOAuthToken()/ScriptApp.newStateToken()

2) Google now offers an oauth2 gmail api (unveiled a few days ago at google I/O 2014)

with these two, you can make your own code to send emails using your own console project etc.