簡體   English   中英

Passport Node.js CORS錯誤

[英]Passport Node.js CORS error

我嘗試了100萬種方法來使護照無法與我的申請一起使用。 每次嘗試登錄到每個提供程序(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請求,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM