我正在从我的客户端向 google oauth 2 API 'https://accounts.google.com/o/oauth2/auth?redirect_uri=http://blah.com&response_type=token&client_id....'
进行 ajax 调用获取访问 token ,但我收到以下错误:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://blah-blah.com' is therefore not allowed access
我希望调用是 ajax,这样当通过
url
进行调用时用户不会受到干扰或 window.location.href
或者换句话说,我怎样才能获得访问 token 以使整个页面不加载,是否可以解决上述错误???
最佳答案
OAuth2 身份验证端点不支持 AJAX 设计。它是身份验证系统的入口点,因此您必须通过重定向到达那里。身份验证的结果再次重定向到您提供的 URL,因此 AJAX 在那里没有多大意义。
关于ajax - 对 oauth2 访问 token 发出 Ajax 请求时出现 CORS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276462/