Javascript Passport OAuth、Twitter登录和CORs
我有一个express.js服务器,它与passport接口,用于Twitter登录。当我从express应用程序提供的页面测试路由时,一切都正常,但我正在尝试使用此服务器与phonegap应用程序接口 当我调用服务器的登录路径(Javascript Passport OAuth、Twitter登录和CORs,javascript,node.js,oauth,cors,twitter-oauth,Javascript,Node.js,Oauth,Cors,Twitter Oauth,我有一个express.js服务器,它与passport接口,用于Twitter登录。当我从express应用程序提供的页面测试路由时,一切都正常,但我正在尝试使用此服务器与phonegap应用程序接口 当我调用服务器的登录路径(http://localhost:3000/auth/twitter)从一个完全独立的客户端应用程序中,我不断遇到以下错误: XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oa
http://localhost:3000/auth/twitter
)从一个完全独立的客户端应用程序中,我不断遇到以下错误:
XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=***************************. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
我相信我正在实现一个正确的CORs中间件,因为我可以调用其他服务器路由没有问题:
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
next();
});
有什么想法吗?这与Twitter特定的问题有关吗?我认为您试图直接点击Twitter api,而不是从nodejs服务器点击,对吗?如果可能的话,你能展示你的客户端代码吗?我也有类似的问题。有决议吗?