Пример #1
0
        protected async Task <ProfileDetails> TryAuthenticateFromAuthCode(string authCode)
        {
            if (Request.Headers.Get("host").Contains("localhost"))
            {
                return(null);
            }
            if (SessionWrapper.Get <ProfileDetails>("ProfileDetails") != null)
            {
                return(SessionWrapper.Get <ProfileDetails>("ProfileDetails"));
            }
            var svc     = new LiveIdAuth();
            var profile = await TryRefreshToken(svc);

            if (profile == null && authCode.Length > 1)
            {
                profile = await UserFromToken(await svc.GetTokens(authCode), svc);
            }
            return(profile);
        }
        protected async Task <ProfileDetails> TryAuthenticateFromAuthCode(string authCode)
        {
            var    svc    = new LiveIdAuth();
            string result = "";

            if (Request.Cookies["refresh_token"] != null && Request.Cookies["refresh_token"].Value.Length > 1)
            {
                result = await svc.RefreshTokens();
            }
            else
            {
                result = await svc.GetTokens(authCode);
            }
            var tokens = new { access_token = "", refresh_token = "" };
            var json   = JsonConvert.DeserializeAnonymousType(result, tokens);
            var userId = await svc.GetUserId(json.access_token);

            return(await InitUserProfile(userId, json.access_token));
        }