护照节点.js CORS 错误
Passport Node.js CORS error
我已经尝试了一百万种方法让护照与我的应用程序一起使用,但无济于事。每次尝试登录每个提供商(Facebook,Google,Twitter,Microsoft)都会导致如下错误:
XMLHttpRequest cannot load https://www.google.com/accounts/o8/ud?openid.mode=checkid_setup&openid.ns=h…2F%2Ftest.sl%2Fauth%2Fgoogle%2Freturn&openid.realm=http%3A%2F%2Ftest.sl%2F.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://test.sl' is therefore not allowed access.
我的应用程序并不复杂,这是我的服务器代码摘要。
var express = require('express');
var ppGoogle = require('passport-google-oauth').OAuth2Strategy;
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/public'));
//There's more config
app.listen(7230);
app.get('/auth/google', passport.authenticate('google'));
app.get('/auth/google/return', passport.authenticate('google', {
successRedirect: '/main',
failureRedirect: '/login'
}));
passport.use(new ppGoogle({
clientID: '',
clientSecret: '',
callbackURL: 'http://test.sl/auth/google/return'
},
function (accessToken, refreshToken, profile, done)
{
console.log('done');
}));
有人知道解决方案吗?这件事快把我逼疯了。
您正在尝试通过AJAX而不是页面导航加载Google的OAuth提示符。
您应该将 AJAX 请求替换为普通导航,
相关文章:
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- XMLHttpRequest在$.ajax工作的地方给出了CORS错误
- 在Polymer中使用核心ajax时出现CORS错误
- 在 AngularJS 和 CodeIgniter3 中开机自检数据时出现 CORS 错误
- AngularJS应用程序中的CORS错误
- Meteor:使用HTTP.get从客户端访问网站(CORS错误)
- Catching'阻止加载混合活动内容'CORS错误
- ajax请求出现CORS错误
- 加载模板时出现AngularJS、Localhost和CORS错误
- 谷歌加 CORS 错误
- 同一域上的 CORS 错误
- 使用 elasticsearch.js 时出现 CORS 错误
- 护照节点.js CORS 错误
- 简单请求中的 Cors 错误:请求标头字段 预检响应中的访问控制-允许-标头不允许授权
- Firefox 和 chrome 的 CORS 错误
- 重定向时出现机架 CORS 错误
- 从localhost使用谷歌联系人api创建联系人时出现CORS错误
- Facebook oEmbed端点CORS错误
- 在Angular中使用解析客户端密钥会导致CORS错误
- 从文件//scheme运行的应用程序出现CORS错误