角/节点/快照/护照 - 连接到Facebook(CORS)时的问题 [英] Angular/Node/Express/Passport - Issues when connecting to facebook(CORS)

查看:259
本文介绍了角/节点/快照/护照 - 连接到Facebook(CORS)时的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的NodeJs服务器上使用Facebook身份验证。我来到了 http://scotch.io/ 的教程,并在使用REST客户端(Postman)时在本地工作,等等)。

i'm trying to use facebook authentication on my NodeJs server. i came to the tutorial of http://scotch.io/ and have it working locally when using a REST client(Postman, etc).

为了改善UI,我将Angular JS用作前端。但是当我在NodeJs后端给我的特定路由调用http.get时,我在chome和firefox中收到以下错误:

To improve the UI i used Angular JS as a front end. but when i call a http.get to my specific route given on the NodeJs back-end i get the following error in chome and firefox:

XMLHttpRequest无法加载 https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri = HTTP% ... 0%2Fapi%2Fauth%2Ffacebook%2Fcallback&安培;范围=电子邮件&安培; CLIENT_ID = 3000000000006。请求资源上不存在访问控制允许源标头。原来'localhost:8080'因此被禁止访问。

XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%…0%2Fapi%2Fauth%2Ffacebook%2Fcallback&scope=email&client_id=3000000000006. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:8080' is therefore not allowed access.

我已经在StackOverflow上尝试了几个解决方案,但仍然没有工作...
我的NodeJs使用Express 4. *和CORS中间件。
为Angular我发现几种方式启用CORS,没有工作到目前为止。

i've tried several solutions on StackOverflow but its still not working... my NodeJs uses Express 4.* and a CORS middleware. for Angular i found several ways to enable CORS, none working so far.

希望你能帮助我:D先谢谢!

I hope you can help me:D Thanks in advance!

推荐答案

您可以使用'window.location =http:// localhost:3000 / auth / facebook Angular Controller 中的,您发送请求到您的 Express Server ,其中包含 passport.authenticate 东西。

You can use 'window.location="http://localhost:3000/auth/facebook"'; in your Angular Controller from where you send the request to your Express Server which contains passport.authenticate stuff.

这将阻止您的角度调用facebook auth对话页面作为AJAX请求。

This will stop your angular to call facebook auth dialogue page as AJAX request.

它适用于我!

这篇关于角/节点/快照/护照 - 连接到Facebook(CORS)时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆