且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

记住在Xamarin表单中注销后最后登录用户

更新时间:2023-12-02 12:58:46

您是否尝试过使用Xamarin中的属性字典.Forms Application类,因为您可以将用户名写入属性字典。


var properties = Xamarin.Forms.App.Current.Properties;


Hi,

We are using Azure AD to authenticate the user in our Xamarin forms app and what we want to achieve in our UWP app that if one user lets says signed in the app and then signed out. On Next login flow Azure AD should show list of user who were logged in on that particular device so user can pick the user and just enter password. 

In our case if we signout the user then it always start the flow from asking the email

Here is code snippet for signout

AuthenticationContext authContext = new AuthenticationContext($"{tenantUrl}/{tenantId}");
                authContext.TokenCache.Clear();

                Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
                var cookieManager = myFilter.CookieManager;
                var cookieUri = new System.Uri(tenantUrl);
                HttpCookieCollection myCookieJar = cookieManager.GetCookies(cookieUri);
                foreach (HttpCookie cookie in myCookieJar)
                {
                    cookieManager.DeleteCookie(cookie);
                }

P.S: Expecting to be issue for UWP AD Package since its working fine on iOS


Arslan Pervaiz
_______________________________
Mark As Answer If It Helps You

Have you tried using the Properties dictionary in Xamarin.Forms Application class as you can write user name to the Properties dictionary.

var properties = Xamarin.Forms.App.Current.Properties;