Passport AngularJS ExpressJS:Access-Control-Allow-Origin不
发布时间:2020-12-17 10:26:22 所属栏目:安全 来源:网络整理
导读:当我尝试使用angular.js的$http模块来授权twitter应用程序时,我总是得到: XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=something. Origin null is not allowed by Access-Control-Allow-Origin. 客户代码: $http(
当我尝试使用angular.js的$http模块来授权twitter应用程序时,我总是得到:
XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=something. Origin null is not allowed by Access-Control-Allow-Origin. 客户代码: $http({ method: 'GET',headers: { "Content-Type": undefined },url: '/oauth/twitter' }); 服务器代码: app.configure(function () { app.use(express.cookieParser()); app.use(express.cookieSession({ secret: 'tobo!',cookie: { maxAge: 3600 }})); app.use(express.session({secret: 'secret'})); app.use(passport.initialize()); app.use(passport.session()); }); app.all('*',function(req,res,next) { res.header("Access-Control-Allow-Origin","*"); res.header("Access-Control-Allow-Credentials",true); res.header('Access-Control-Allow-Methods','GET,PUT,POST,DELETE'); res.header("Access-Control-Allow-Headers",'Access-Control-Allow-Headers","Origin,X-Requested-With,Content-Type,Accept'); next(); }); app.get('/oauth/twitter',passport.authenticate('twitter'),function (req,res) { // The request will be redirected to Twitter for authentication,so this // function will not be called. console.log('ouath/twitter') }); app.get('/oauth/twitter/callback',passport.authenticate('twitter',{ successRedirect: '/',failureRedirect: '/login' })); 但是如果我使用带有oauth / twitter地址的超链接,它就可以了.我不知道是什么问题.大多数人说不允许来源,但’*’应该允许每个地址连接到服务器.
我有同样的问题,我找到的唯一解决方案是使用超链接(正如你在帖子中所说).我认为你不能出于安全原因使用ajax请求.但是,使用超链接为我工作,我可以授权我的用户.
你为什么不使用超链接?有问题吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |