Logout from Facebook auth provider RRS feed

  • Question

  • I have a WP8 app that uses Facebook authentication, everything is fine but can't find a way to logout and let the user login with other Facebook credentials.

    On emulator Facebook login is displayed only at 1st startup in all other cases nothing is asked and it keeps reusing old credentials, same happen on phone, I have to remove/reinstall app in order to have loging screen back.
    Tried Logout() and setting CurrentUser to null but looks like credentials are stored somewhere on the phone.
    Any hint?

    Corrado Cavalli [Microsoft .NET MVP-MCP] UGIdotNET - Weblog: twitter:

    Wednesday, October 16, 2013 8:49 AM

All replies

  • When you say you are calling logout are you calling MobileServiceClient.Logout?  This is the correct way to logout.  Are you sure that you are clearing all application data after logout so you are not seeing stale Information?

    After calling Logout you would need to call MobileServiceClient.LoginAsync again.

    Bret Bentzinger (MSFT) @awehellyeah

    Friday, October 18, 2013 11:01 PM
  • Hi Bret,
    I don't save any application data and it happens even re-launching the application, the only way to get the Facebook login window is to close/reopen the emulator or reinstall the application on device.
    There's certainly some data stored somewhere but can't figure how to clear it, since it happens even relaunching the app don't think that reinstantiating the mobile service would help.

    Anything i can check?



    Corrado Cavalli [Microsoft .NET MVP-MCP]
    UGIdotNET -

    Wednesday, October 23, 2013 7:46 AM
  • Since the Facebook authentication (and all of the authentication providers for that matter) use the WebBrowser control to handle that actual login, it sounds like the browser is caching the user's login cookie. So even though your user is not logged in to Mobile Services, when you call LoginAsync, the WebBrowser is launched and navigated to Facebook, which immediately reads the user's cookie and logs them in, returning a success to the Mobile Services handler - essentially auto-logging them in each time.

    To fix it, you would have to log the user out of their browser-based Facebook session somehow. I dont know how to best achieve that, but maybe it will point you in the right direction.

    Wednesday, October 23, 2013 1:56 PM
  • I read Brian's response and thought he was correct. Thanks Brian! So I investigated the Azure Mobile Services Git Hub project and looked at the source.  They are in fact using a browser control.

    This code should work:

    private async void Logoff_Click(object sender, RoutedEventArgs e)
                user = null;
                WebBrowser dummyBrowser = new WebBrowser();
                await WebBrowserExtensions.ClearCookiesAsync(dummyBrowser);
    If you need something more concrete you can always download the Azure Mobile Service Client SDK from Github and customize it to your needs.

    Bret Bentzinger (MSFT) @awehellyeah

    Wednesday, October 23, 2013 4:59 PM
  • That was the trick!

    Just tried and everything works fine now (wonder why AMS don't handle this automatically though)

    Thanks Brian and Bret!

    Corrado Cavalli [Microsoft .NET MVP-MCP]
    UGIdotNET -

    Thursday, October 24, 2013 7:30 AM