0

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:

OAuth
(source: google.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Skills
  • 113
  • 2
  • 7
  • Related Q: https://stackoverflow.com/questions/23207209/which-google-oauth-flow-is-good-for-web-application-not-reachable-from-the-inter – Skills Mar 31 '17 at 16:07
  • This seems similar to this [SO thread](http://stackoverflow.com/questions/10456174/oauth-how-to-test-with-local-urls). – ReyAnthonyRenacia Apr 01 '17 at 11:13
  • @noogui That method still uses a redirect to localhost. I can not have a web server at all in my case. How do I do google oath with no web server? – Skills Apr 02 '17 at 22:23
  • Maybe you want this: https://stackoverflow.com/questions/28751995/how-to-obtain-google-service-account-access-token-javascript – artamonovdev Apr 03 '17 at 14:21

0 Answers0