【发布时间】:2016-04-26 15:50:03
【问题描述】:
网址:http://local.m2.xxx.com/login
this.$http.post('https://accounts.google.com/o/oauth2/token', {
'code': code,
'redirect_uri': '***',
'client_id': '******',
'client_secret': '****',
'grant_type': 'authorization_code'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.success((data, status, headers, config)=> {
deferred.resolve(data);
})
.error((data, status) => {
deferred.reject(data);
});
我还将 Authorized JavaScript origins 设置为 http://local.m2.xxx.com
但仍收到 XMLHttpRequest 无法加载 https://accounts.google.com/o/oauth2/token。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin '***' 不允许访问。响应的 HTTP 状态代码为 405。
找不到解决办法
【问题讨论】:
-
@Quentin 来自谷歌开发者控制台imgur.com/TmiBKyT
-
您熟悉 CORS 及其工作原理吗?
-
@DanielNalbach 我当然知道 CORS,但我是说我已经在 google 上注册了我的域
-
您确定您使用的是正确的端点吗?对于客户端 JS,我相信端点是:accounts.google.com/o/oauth2/v2/auth 至少根据 Google 的 Using OAuth 2.0 for Client-side Applications 页面
标签: javascript angularjs xmlhttprequest google-login