我正在尝试在我的 NodeJs 服务器上使用 facebook 身份验证。我来到了http://scotch.io/的教程并在使用 REST 客户端(Postman 等)时让它在本地工作。
为了改进 UI,我使用 Angular JS 作为前端。但是当我调用 http.get 到我在 NodeJs 后端给出的特定路由时,我在 chome 和 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” header 。因此不允许访问源 'localhost:8080'。
我已经在 StackOverflow 上尝试了几种解决方案,但仍然无法正常工作... 我的 NodeJs 使用 Express 4.* 和 CORS 中间件。 对于 Angular,我找到了几种启用 CORS 的方法,但目前没有一种有效。
我希望你能帮助我:D 提前致谢!
最佳答案
您可以在发送请求的 Angular Controller 中使用 'window.location="http://localhost:3000/auth/facebook"';
到您的 Express Server,其中包含 passport.authenticate
内容。
这将阻止您的 Angular 将 facebook 身份验证对话页面作为 AJAX 请求进行调用。
它对我有用!
关于facebook - Angular/Node/Express/Passport - 连接到 facebook (CORS) 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23753965/