Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging out from facebook when using MVC 5 OWIN

I have an MVC 5 web app that has facebook authentication set up and working nicely. User clicks "Facebook" on the login page, signs in to Facebook and that authenticates with our web site. If the user logs out, the call to AuthenticationManager.SignOut() logs out of the web site correctly, but if the user then goes back to the login page and clicks "Facebook" again they are immediately signed in without having to sign in to facebook.

So my question is, how do I configure MVC 5 OWIN facebook login so that the user is signed out of facebook when they sign out of the web site, or to put it another way, prevent caching of the authentication for the next sign in. I don't want a users facebook login to be silently cached in case they are sharing a browser with other users.

like image 641
fubaar Avatar asked Dec 02 '25 01:12

fubaar


1 Answers

The only way that I know to do this would be to tie an event to your log out button or link and use the Facebook Javascript SDK to actually perform the Facebook logout for you.

<a href="/Account/Logout" id="Logout">LogOut</a>

<script type="text/javascript">
   $(function(){
      $("#Logout").on("click", function(e){
        if(confirm("This will also log you out of Facebook.  Proceed?")){
           FB.logout(function(response) {
           // Person is now logged out
           });
         }else{ 
            //do not allow the link to continue and sign our of your site.
            //This is optional and allows you to provide options
            e.PreventDefault();
         }
      });    
   });
</script>

You could actually use the confirm dialog to ask if they want to be signed out of Facebook as well. A confirm would mean yes, a not confirm would mean no, just sign me out of your site. Again, using the SDK and a little bit of control logic should provide the results you need.

like image 154
Tommy Avatar answered Dec 04 '25 15:12

Tommy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!