Node Passport-facebook login in Facebook Page Tab application

蓝咒 提交于 2019-12-12 16:21:40

问题


I'm developing a web application in NodeJS and AngularJS, that is a PageTab application to facebook.

For the login I'm using the library Passport-facebook.

My middleware is:

passport.authenticate('facebook', {
        display: 'popup',
        scope: ['read_stream', 'publish_actions', 'email', 'user_photos']
    })

The application works if i'm outside the tab of facebook, but when I try into facebook tab, I get an error:

[Error] Refused to display'Http....'in a frame because it set 'X-Frame-Options' to 'DENY'. (login, line 0)
[Error] SecurityError: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

Because facebook permission dialog can't be launched from an iFrame

What can I do to fix, keeping the session management with passport strategy?


回答1:


At the end what I did:

  • When user is not logged in, instead of res.redirect("/auth/facebook"); I did res.render("authorize");
  • in the authorize.html page I have window.top.location = window.location + "auth/facebook";
  • an instead of Passport.authenticate("facebook", { successRedirect: "/", failureRedirect: "/login" } ) I did Passport.authenticate("facebook", { successRedirect: appHomePage, failureRedirect: appHomePage } ) with appHomePage set to the absolute URL of the facebook app (e.g. https://apps.facebook.com/8480657996/

Note that it is useful to use environment vars to aviod hard coding the app home page in your app



来源:https://stackoverflow.com/questions/26021090/node-passport-facebook-login-in-facebook-page-tab-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!