FB.logout() - no access token - “Log in as Different User”

纵然是瞬间 提交于 2019-12-12 21:02:45

问题


This question is in relation to this question: FB.logout() called without an access token

I had a question i was hoping someone could help with.

I get everything in the link above, but how do you handle when someone uses a public computer and leaves themselves logged in to FB by accident? Then a new user tries to log in to an app, but it is not them. I want to have a button to log them out of FB altogether to "log in as a different user".

I cannot do that until they authorize the app, right? So they need to authorize the app under someone else's account and then log out? There has to be another way.

Any feedback would be great - tried searching for a while on this, but to no avail. I might be over thinking it, but there should be some way to "log in as a different user".


回答1:


You can do something like:

FB.getLoginStatus(function(response) {
    if (response.status === "connected") {
        FB.api("me", function(response2) {
            //  notify the user he is logged in as response2.name, and if it's not him call FB.logout
        }
    }
    else {
        // prompt the user to login
    }
}



回答2:


Modify your logout to something like this :-

              function logout(response){
        console.log("From logout" + response);
        if(!response.authResponse){
            window.location = "/web/login/";
            return;
        }

           FB.logout(function(response){
               FB.Auth.setAuthResponse(null,'unknown');  
                 logout();
           });
        }

i.e keep on sending logout request to Facebook till the actual logout happens.




回答3:


Try to use Session and save the user's ID in that session. You can control the expiration time of that session( by default its 20 minute if the user doesn't have any activity on the page) then in each page Load even check whether the season is still active for that user or not.

page Load event:

if(Session["LoggedIn"]==null)
{
Response.Redirect("~/Login.aspx");
}

This code above will redirect user to login page of your website if the session has expired.



来源:https://stackoverflow.com/questions/10744892/fb-logout-no-access-token-log-in-as-different-user

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