【问题标题】:How to signout from an android app using azure adb2c and app- auth如何使用 azure adb2c 和 app-auth 从 android 应用程序中注销
【发布时间】:2018-08-06 06:26:17
【问题描述】:
我使用以下教程使用 appauth 在我的 android 应用程序中集成了 azure adb2c 的登录
Android appauth.
教程没有提到如何退出应用程序。
azure 文档中也没有提及这方面的内容。
知道如何做到这一点吗?
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签:
android
azure
azure-active-directory
azure-ad-b2c
appauth
【解决方案1】:
您可以调用您的 MobileServiceClient.LogoutAsync();
然后您必须清除浏览器中的 cookie 才能登录。根据设备上安装的应用程序,它可能是 Web 视图或 Chrome 自定义选项卡。
如果是WebView,你可以通过调用清理OAuth2.0的cookies:
CookieManager.Instance.RemoveAllCookies(null);
CookieManager.Instance.Flush();
如果 Oauth2.0 登录使用 Chrome 自定义选项卡,那么您可以使用浏览器自定义选项卡为您的 oauth 调用注销 url。 (示例答案来自:https://github.com/Azure/azure-mobile-apps-ios-client/issues/51#issuecomment-393294895)
var logoutUrl = "https://login.windows.net/common/oauth2/logout";
var uri = Android.Net.Uri.Parse(logoutUrl);
var builder = new CustomTabsIntent.Builder();
var customTabsIntent = builder.Build();
customTabsIntent.LaunchUrl(MainActivity, uri);
但这不会在注销后自动关闭浏览器...我还没有弄清楚如何做到这一点?
【解决方案2】:
Azure Mobile Android SDK 提供了帮助我们注销的方法,我们可以使用MobileServiceClient.logout() 来实现。
这里是原始代码供您参考:
/**
* Log the user out of the Mobile Service
*/
public ListenableFuture logout() {
final SettableFuture logoutFuture = SettableFuture.create();
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
mCurrentUser = null;
logoutFuture.set(null);
return null;
}
}.execute();
return logoutFuture;
}
Android Studio 中 SDK 的屏幕截图:
MSDN 中的这个帖子可能对你有帮助:
Cant logout MobileServiceUser from app