openFB logout opens Facebook?

Using openFB to authenticate our user, and the login process works, we get a token and can subsequently use the graph api.

Now to logout: Our logout redirect is set correctly on our Facebook app settings, etc. BUT:

Logging out works, in that the token is killed so the app no longer has permissions, but the logout() method makes a request to https://www.facebook.com/logout.php, which pops up a new browser window and for some reason redirects to https://www.facebook.com/home.php, then never closes.

So, what’s wrong here? Shouldn’t this window close automatically, and why does it redirect to Facebook’s home?

Thanks!

1 Like

any ideas on this anyone?

That’s because openFB has a bug, it would close just fine if the variable runningInCordova was set to true, but the problem is that the variable will never be set to true because the event deviceready inside openFB will never be called, and that’s where the variable is set to true.

heres the lines inside openFB that would make the window close:

if (runningInCordova) {
                setTimeout(function() {
                    logoutWindow.close();
                }, 700);
            }

so is there a way around it?

I got it working with an extremely ugly work around by hosting on heroku a static page with just the logoutcallback.html content:

<html>
<body>
<script>
    // alert('closing');
    window.close();
</script>
</body>
</html>

So the problem with this library is that you need to HOST a page on the internet just to CLOSE that f***** window with the script window.close();.
The path should be like: http://www.any-domain.com/logoutcallback.html, then you have to add it the htttp://www.any-domain.com/ to your Site URL in your facebook app Settings, and add the url http://www.any-domain.com/logoutcallback.html in Valid OAuth redirect URIs located in Advanced Settings.

I created an node.js app using this link( or you could just create a default node.js app, but I did this because I’m a noob in node.js and tired of trying to get this work). You will have to download the code of the app that you just created and delete all the code inside index.html and insert the content of logoutcallback.html. After that you open the server.js and add this line:

app.get('/logoutcallback.html', function(req,res){
  res.render("index.html");
});

Savte it, upload to heroku and you’re done. Inside openFB.js you just need to modify this:

logoutRedirectURL = 'https://www.any-domain.com/logoutcallback.html',

But for the rest you don’t need to make any modification on your openFB.js, just follow the steps in the docs and you will be ok.

Here is how I called the logout function if anyone is wondering:

$scope.logout=function(){
    openFB.logout(
      function() {
          $state.go('login');
      },
      errorHandler);
    localStorage.clear();
    sessionStorage.clear();
  }

The openFB.js library is really useful but is not complete, the author should have warned about this horrible workaround that MUST be done. If there’s anyone else with a better solution please post it and stop this pain to other people haha

thanks a lot, wow sounds complicated, I will give it a go thanks again @betoharres :slight_smile:

well it’s not that hard, I just typed every single step. If you have any doubt post it here

I did that, I created the logoutcallback.html and uploaded that on my server. I also added the Valid OAuth redirect URIs on Facebook. As for the rest, here is what I found:

1.- Site URL on Facebook - I do not use Site URL because my app runs on mobile devices and therefore it is not relevant for me.

2.- I created the node.js app using Heroku as per your instructions. After creating the node.js app, I could not see any index.html file which confuse me here. I have an index.js but I cannot put html inside as it is a JavaScript file.

3.- You said to open server.js. However, I don’t have any server.js. Where this file was supposed to come from? I created the node.js with Heroku and it didn’t create any server.js. I created only the following files:

.gitignore
app.json
index.js
package.json
Procfile
public
README.md

So what I am thinking is that instead of uploading the logoutcallback.html to my server, I supposed to upload that to the Heroku server along with the node.js app I just created. But if that is correct, what’s that index.html and server.js you mentioned that cannot be seen anywhere?

Yes you could have just putted the logoutcallback.html on your server. I don’t owe one so that’s why I used heroku, you can skip all this bullshit if you want, just point the urls in the facebook app settings to your logout.html that you hosted

The site URL must be specified, if you open openFB.js at line ~187 you will see a warning saying that you have to fill the Site URL in order to get it working.

those files are from the app that heroku has created, but somehow it doesn’t have any folder and files from a fresh new ionic project. I checked the link and it’s the link I’ve used. You should be fine if you just create a standard node.js app and upload it to heroku.

You can use divhost if you want, it is like heroku but just for static pages. I haven’t test it though.

ok that works thanks