在为oauth2访问令牌发出Ajax请求时出现CORS问题

时间:2017-04-07 10:59:10

标签: ajax oauth google-api oauth-2.0 cors

我正在从我的客户端向google oauth 2 API SELECT product_name, count(*), SUM( (product_name = 'pro_a1' and price between 20 and 30)::int) as cnt_a1, SUM( (product_name = 'pro_b1' and price between 50 and 70)::int) as cnt_b1 FROM Products WHERE (product_name = 'pro_a1' and price between 20 and 30) OR (product_name = 'pro_b1' and price between 50 and 70) GROUP BY product_name; 发出ajax调用以获取访问令牌,但我收到以下错误:

  

对预检请求的响应未通过访问控制检查:否   请求中存在“Access-Control-Allow-Origin”标头   资源。因此不允许来源“http://blah-blah.com”   访问

我希望调用是ajax,以便在通过'https://accounts.google.com/o/oauth2/auth?redirect_uri=http://blah.com&response_type=token&client_id....'url进行呼叫时不会打扰用户,或者换句话说,我如何获得访问令牌以便整个页面无法加载,是否可以解决上述错误???

1 个答案:

答案 0 :(得分:3)

OAuth2 auth端点不支持AJAX设计。它是身份验证系统的入口点,因此您必须通过重定向到达那里。身份验证的结果再次是重定向到您提供的URL,因此AJAX在那里没有多大意义。

相关问题