Search code examples
google-apps-scriptgmail-addons

Communication between Gmail Addon and external site


I'm building a Gmail Add-on where user needs to authenticate to a service to use it. To do that, we have a site that act as a proxy for multiple service (for example, Dropbox and Box). The way that it works, user selects a service to authenticate, it is redirected to their oauth page, and when callback is received, token is generated on our own service and send back our token, not theirs.

So flow would be...

1. User clicks login on Gmail Add-on
2. Opens own site (third party) that contains multiple login options.
3. Selects one that redirects user inside it on a new oAuth service.
4. Our service (inside the open window) receives oAuth token and creates a new token.
5. This new token is sent back to add-on.

What I wonder is how can I get/send/proceed with this last step, once we got our token, is there a way to send it back to the gmail add-on? On other platforms, we could read redirections, send sockets, but I don't get how it can be achieved on google apps script.

Any ideas? 🧐


Solution

  • What I was asking can be achieved using the class ScriptApp. Basically, external site can use the usercallback script to return the token so the flow would be:

    1. Generate a callback state.
    2. Send the redirect_uri with state token.
    3. You can do whatever you want on this step (on external site).
    4. Send back in url param the information (in my case, token) that you need.
    5. Callback response can be get on your callback action.