Google oauth 400 response: No 'Access-Control-Allow-Origin' header is present on the requested resource
<p>I'm trying to make request from client-side javascript to the google oauth endpoint (<a href="https://accounts.google.com/o/oauth2/v2/auth" rel="noreferrer">https://accounts.google.com/o/oauth2/v2/auth</a>) with a google calendar scope. Thing is, I can't use google's javascript client, because I'm actually using webpack, and I don't want to have separately include a javascript script outside of my bundle.js.</p>

<p>So instead, I'm using axios (<a href="https://github.com/mzabriskie/axios" rel="noreferrer">https://github.com/mzabriskie/axios</a>) to make the HTTP GET to the aforementioned token endpoint. Here's what my request looks like:</p>

<pre><code>https://accounts.google.com/o/oauth2/v2/auth?response_type=token&amp;client_id={client id here}&amp;nonce=c8ef445540186351d9108ad64d7a5b65&amp;scope=https:%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar
</code></pre>

<p>I generated the nonce using the crypto-js library's MD5 function. Here are the request headers:</p>

<pre><code>Accept:application/json, text/plain, */*
Origin:http://localhost:8000
Referer:http://localhost:8000/admin
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
</code></pre>

<p>The response I get from google looks like this:</p>

<pre><code>alt-svc:quic=":443"; ma=2592000; v="32,31,30,29,28,27,26,25"
alternate-protocol:443:quic
cache-control:no-cache, no-store, max-age=0, must-revalidate
content-encoding:gzip
content-type:text/html; charset=utf-8
date:Mon, 18 Apr 2016 07:16:21 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:GSE
status:400
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block
</code></pre>

<p>And I see this log in my chrome devtools console:</p>

<pre><code>XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/v2/auth?response_type=token&amp;client_id={client id here}&amp;scope=https:%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 400.
</code></pre>

<p>I've made sure that in my google app console, under the corresponding client id, I've added <a href="http://localhost:8000" rel="noreferrer">http://localhost:8000</a> to the "Authorized Javascript Origins" field, and I've made sure to enable authorization for the google calendar api. I've read that the web client implicit auth flow doesn't use the redirect uri, but I've tried filling that out regardless (I've tried the values <a href="http://localhost:8000" rel="noreferrer">http://localhost:8000</a> and <a href="http://localhost:8000/admin" rel="noreferrer">http://localhost:8000/admin</a>, which is the page I'm sending my request from). Having spent hours googling this, I've found nothing to suggest that what I'm doing shouldn't work.</p>

<p>So my question is, if I've allowed <a href="http://localhost:8000" rel="noreferrer">http://localhost:8000</a> as an authorized origin for my client ID, why am I still not able to send a request (albeit via javascript) to that auth endpoint?</p>