0

I have made an application where the user is required to sign into their google account before they can access my app. However I don't know how the user can log out of their Google account from within my app. Could anyone point me in the right direction. Thanks

My Code is as fallows for logging into my app Using Google

public class Menu extends AppCompatActivity {
    private MobileServiceClient mClient;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        try {
            mClient = new MobileServiceClient(
                    "https://craigsapp.azure-mobile.net/",
                    "BTkcgnFQvevAdmmRteHCmhHPzdGydq84",
                    this
            );
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        authenticate();
    }
    private void authenticate() {
        mClient.login(MobileServiceAuthenticationProvider.Google, new UserAuthenticationCallback() {

            @Override
            public void onCompleted(MobileServiceUser user, Exception exception, ServiceFilterResponse response) {
                if (exception == null) {
                    Log.w("TodoActivity", "Logged in");

                } else {
                    Log.e("TodoActivity", "They aren't logged in");
                }
            }
        });
    }
    }
Craig Gallagher
  • 1,613
  • 6
  • 23
  • 52

1 Answers1

1

There should be simple logout() function on the mClient. I assume you used Azure Mobile services

So just create a button, assign onclick with it, that will call this function and it should work.

adsamcik
  • 1,265
  • 12
  • 14
  • I tried that and it didn't seem to work. I will try another few things. Any other ideas or should `logout()` defiantly work – Craig Gallagher Mar 24 '16 at 12:24
  • `logout()` must work since the only thing it does is `mCurrentUser = null;`, there is nothing that could fail ^^. Are you sure that the user is still logged? How do you verify that it doesn't work? – adsamcik Mar 24 '16 at 12:57
  • Because when I relaunch the application Goole doesn't ask for the users credentials. – Craig Gallagher Mar 24 '16 at 13:32
  • Here is what I have `switch(id){ case R.id.instructions: Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_SHORT).show(); mClient.logout(); break; }` – Craig Gallagher Mar 24 '16 at 13:35
  • I read through it more and I found that this is common issue. My guess is that the user is logged out, but Google knows the user already logged in and authenticated in your app, so the next time he tries to login, it is automated and in the background. It seems that the info about login is saved in cookie, but I am not sure where exactly. – adsamcik Mar 24 '16 at 13:49
  • I found something that might help https://gist.github.com/ChrisRisner/5416548#file-logout-java – adsamcik Mar 24 '16 at 13:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/107237/discussion-between-craig-gallagher-and-adsamcik). – Craig Gallagher Mar 24 '16 at 15:23
  • I got it working in the end by fallowing this http://stackoverflow.com/questions/10977288/clear-application-cache-on-exit-in-android – Craig Gallagher Mar 24 '16 at 16:04