Passport Node.js CORS错误

Jac*_*Guy 2 javascript cors express passport.js

我已经尝试了一百万种方法让护照与我的申请一起工作无济于事.每次尝试登录每个提供商(Facebook,谷歌,Twitter,微软)都会导致如下错误:

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.
Run Code Online (Sandbox Code Playgroud)

我的应用程序并不复杂,这里是我的服务器代码的摘要.

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');
}));
Run Code Online (Sandbox Code Playgroud)

谁知道解决方案?这件事让我抓狂.

SLa*_*aks 7

您正尝试通过AJAX而不是页面导航加载Google的OAuth提示.

您应该使用普通导航替换您的AJAX请求,