Skip to content

Instantly share code, notes, and snippets.

@ricalo
Last active August 29, 2015 14:18
Show Gist options
  • Save ricalo/d65837b9f83c2396b2ac to your computer and use it in GitHub Desktop.
Save ricalo/d65837b9f83c2396b2ac to your computer and use it in GitHub Desktop.
Function to remove the entries in the ADAL token cache, delete the cookies and set the relevant objects to null.This allows the app to disconnect from Office 365 and then connect with a different user.
private void disconnect(){
//Clear tokens.
AuthenticationManager
.getInstance()
.getAuthenticationContext()
.getCache()
.removeAll();
//Set manager objects to null.
MailManager.resetInstance();
DiscoveryManager.resetInstance();
AuthenticationManager.resetInstance();
//Clear cookies.
if(Build.VERSION.SDK_INT >= 21){
CookieManager.getInstance().removeSessionCookies(null);
CookieManager.getInstance().flush();
} else {
CookieManager.getInstance().removeSessionCookie();
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().sync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment