Angular/Node/Express/Passport - 连接到 facebook(CORS) 时出现问题 [英] Angular/Node/Express/Passport - Issues when connecting to facebook(CORS)

查看:29
本文介绍了Angular/Node/Express/Passport - 连接到 facebook(CORS) 时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 NodeJs 服务器上使用 Facebook 身份验证.我来到了 http://scotch.io/ 的教程,并在使用 REST 客户端(邮递员, 等等).

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 作为前端.但是当我调用 http.get 到我在 NodeJs 后端给出的特定路由时,我在 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&scope=email&client_id=3000000000006.请求的资源上不存在Access-Control-Allow-Origin"标头.因此不允许访问源 '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"'; 中使用 'window.location="http://localhost:3000/auth/facebook"';strong>Angular Controller,您从这里向包含 passport.authenticate 内容的 Express Server 发送请求.

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.

它对我有用!

这篇关于Angular/Node/Express/Passport - 连接到 facebook(CORS) 时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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