Logout does not work when using Microsoft Authentication Library (MSAL)

随声附和 提交于 2019-12-07 19:16:29

问题


I have a Xamarin.Forms iOS/Android app and have to authenticate the user against a Microsoft Azure B2C AD.

I have added the Microsoft.Identity.Client NuGet and using this for authentication.

Login works fine and I am able to use the returned token to call an Azure hosted service of our own.

The trouble is that when I try to logout the user it does not work as expected.

If the user logs out and immediately after kills the app, the next time the app is started the login screen is presented as expected.

To kill the app on iOS I go to app-switcher with double click home button and the swipe up.

But if the user does NOT kill the app, but instead presses my login button (triggers a call to AcquireTokenAsync()) the sign in screen is NOT presented by Microsoft.Identity.Client but instead a valid token is immediately returned and the app is able to use this token for service calls, i.e. it is a valid token.

Next time the app is launched the token is no longer there and the login screen appear.

The strange this is that when I run the sample from GitHub/active-directory-b2c-xamarin-native I see the same behaviour. So I suspect it is a bug in the MSAL component from Microsoft.

According to the sample logout should simply be done with calling

PublicClientApplication.UserTokenCache.Clear(PublicClientApplication.ClientId);

I have also tried with adding

foreach (var user in PublicClientApplication.Users)
{
     user.SignOut();
}

without any change.

Any suggestions?


回答1:


This is happening because the service does not support certain features that would result in a user sign out. This is still a work in progress.




回答2:


Just add following line in Droid Project:

CookieManager.Instance.RemoveAllCookie();

in iOS,

 foreach (var cookie in NSHttpCookieStorage.SharedStorage.Cookies)
 {
   NSHttpCookieStorage.SharedStorage.DeleteCookie (cookie);
 }

and for more details visit this link https://developer.xamarin.com/guides/xamarin-forms/cloud-services/authentication/azure/



来源:https://stackoverflow.com/questions/37792244/logout-does-not-work-when-using-microsoft-authentication-library-msal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!