WebAuthenticationBroker保持登录状态 [英] WebAuthenticationBroker stay logged in

查看:62
本文介绍了WebAuthenticationBroker保持登录状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebAuthenticationBroker类在我的应用程序(Metro App C#)中使用Facebook登录。但是当用户检查"保持登录状态"时他每次都需要登录。任何让用户保持登录状态的想法,或者如何让用户保持登录状态
in 15分钟?

I'm using the WebAuthenticationBroker class to log in with Facebook in my app (Metro App C#).However when the user checks "Stay logged in" he needs to log in each time. Any ideas to let the user stay logged in, or how to let the user stay logged in for 15 minutes?

 private async System.Threading.Tasks.Task loginFacebook()
    {
            var emailadres = "";
            var contactnaam = "";
            try
            {
                var appId = "MyAppID";
                var callbackUrl = "https://www.facebook.com/connect/login_success.html";
                var url = "https://www.facebook.com/dialog/oauth?client_id=" + appId +
                            "&redirect_uri=https://www.facebook.com/connect/login_success.html" +
                            "&scope=email&display=popup&response_type=token";
                var webAuthenticationResult =
                    await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, new Uri(url), new Uri(callbackUrl));

                if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    var client = new HttpClient();
                    var indexOfToken = (webAuthenticationResult.ResponseData.IndexOf("access_token", StringComparison.Ordinal) + 13);
                    var tokenString = webAuthenticationResult.ResponseData.Substring(indexOfToken);
                    var token = tokenString.Substring(0, tokenString.IndexOf("&", System.StringComparison.Ordinal));

                    var data = await client.GetStringAsync(@"https://graph.facebook.com/me?fields=name,email&format=json&access_token=" + token);
                    var serializer = new DataContractJsonSerializer(typeof(UserInfo));
                    UserInfo userInfo;
                    using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
                    {
                        userInfo = (UserInfo)serializer.ReadObject(stream);
                    }

                    emailadres = userInfo.email;
                    contactnaam = userInfo.name;

                }
                else
                {
                    var dialog = new MessageDialog("Error occurred.  Please check your internet connection and credentials.");
                    await dialog.ShowAsync();
                }
            }
            catch (Exception)
            {
                var dialog = new MessageDialog("Error occurred.  Please check your internet connection and credentials.");
                dialog.ShowAsync();
            }
    }

推荐答案

嗨  Optimouse,

我想将您重定向到适当的论坛以获得更好的回复。 

I would like to redirect you to appropriate forum for better responses. 


这篇关于WebAuthenticationBroker保持登录状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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