示例#1
0
        public static bool AutoSignOn(Func <string> getSessionCookieValue, Func <TransferSignOnInfo> getTransferSignOnInfo)
        {
            ISSOClientProvider cp  = IocInstance.Container.Resolve <ISSOClientProvider>();
            var sessionCookieValue = getSessionCookieValue();

            if (!string.IsNullOrEmpty(sessionCookieValue))
            {
                var encrypt = cp.GetEncryptor();
                try
                {
                    var decrypted = encrypt.Decrypt(sessionCookieValue);
                    if (!string.IsNullOrEmpty(decrypted))
                    {
                        IJsonSerializer js      = IocInstance.Container.Resolve <IJsonSerializer>();
                        var             session = js.Deserialize <Session>(decrypted);
                        cp.SaveSession(session);
                        return(true);
                    }
                }
                catch
                {
                }
            }
            else
            {
                var transferSignOnInfo = getTransferSignOnInfo();
                if (transferSignOnInfo != null)
                {
                    var r = cp.TransferSignOn(transferSignOnInfo);
                    return(r.Status == ResponseStatus.Success);
                }
            }
            return(false);
        }
示例#2
0
        public static void SetSessionCookie()
        {
            if (IsAuthenticated && HttpContext.Current.Response != null)
            {
                SetClientCookie();

                IJsonSerializer    js   = IocInstance.Container.Resolve <IJsonSerializer>();
                ISSOConfiguration  sc   = IocInstance.Container.Resolve <ISSOConfiguration>();
                ISSOClientProvider cp   = IocInstance.Container.Resolve <ISSOClientProvider>();
                var        val          = js.Serialize(CurrentSession);
                var        encrypt      = cp.GetEncryptor();
                var        encryptedVal = encrypt.Encrypt(val);
                HttpCookie c            = new HttpCookie("sid", encryptedVal);
                c.Path = "/";
                //c.Domain = CurrentClient.BaseUrl;
                c.Expires = DateTime.Now.AddMinutes(sc.SessionExpiredTimeOutMunites);
                HttpContext.Current.Response.Cookies.Remove("sid");
                HttpContext.Current.Response.Cookies.Add(c);
            }
        }