I am writing a single page application with HTML and JavaScript. This application will be used by saving the HTML and JS file to the local disk and double clicking on the HTML file.
I would like to be able to have the user send email using the Google Api.
I have been researching this for a few days and I found that there is no good way to do this. I went to this page: https://developers.google.com/identity/choose-auth and on the left hand side there are links to guides. Each option has has its problem:
OAuth 2 . 0 for JavaScript Web Apps: Requires a HTTP server that Google redirects to. I can not, yes I can not, provide a HTTP server for redirecting back to http:\\localhost because this HTML file is going to be loaded from the local disk with the file:\\ protocol.
OAuth 2 . 0 for TV & Device Apps: I thought this might work but when I use a XMLHttpRequest object in my HTML JavaScript code to send a post to https:\\accounts.google.com/o/oauth2/device/code then I get this error in me console:
10:43:39.124 Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https:\\accounts.google.com/o/oauth2/device/code. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). 1 (unknown)
The only way, which is not really user friendly is by using the guide called "OAuth 2 . 0 for Mobile & Desktop Apps" and using the option called "Option 3: Manual copy/paste" but it says on there "This option may be discontinued in the future and should only be used if the choices above are not viable." which I also don't like. Example of that:
(source: google.com)