记住在Xamarin表单中注销后最后登录用户 [英] Remember Last Logged In User After Signout in Xamarin Forms

查看:69
本文介绍了记住在Xamarin表单中注销后最后登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我们正在使用Azure AD对我们的Xamarin表单应用中的用户进行身份验证,以及我们希望在我们的UWP应用中实现的目标,即如果一个用户让我们签名在应用程序中然后退出。在下一个登录流程中,Azure AD应显示在
登录该特定设备的用户列表,以便用户可以选择该用户并输入密码。 


在我们的案例中如果我们注销用户,那么它总是从询问电子邮件开始流程


以下是注销的代码段




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(myCookieJar中的HttpCookie cookie)

                {

                    cookieManager.DeleteCookie(cookie);

                } b $ b b:
PS:由于UWP广告套餐在iOS上运行正常,因此可能会出现问题。




Arslan Pervaiz

_______________________________

标记为答案如果有帮助您

解决方案

您是否尝试过使用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;


这篇关于记住在Xamarin表单中注销后最后登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆