示例#1
0
        internal eBayHttpContext()
        {
            this._loginInfo = null;
            this._currentCtx = HttpContext.Current;

            if (_currentCtx == null) throw new InvalidOperationException(@"Support Web Application Only");

            if (false == _currentCtx.Items.Contains(CTX_MEMBER_ID))
            {
                string uid = this.MemberId;

                _currentCtx.User = new System.Security.Principal.GenericPrincipal(
                    new System.Security.Principal.GenericIdentity(uid),
                    new string[] { @"User" });
            }
        }
示例#2
0
        private static UserAuthData CreateAuthData(string uid)
        {
            UserAuthData data = new UserAuthData();

            data.UserId = uid;
            data.RemoteAddress = eBayHttpContext.GetRemoteAddress();
            data.LastAccessed = DateTime.UtcNow;

            return data;
        }
示例#3
0
        private static HttpCookie MakeAuthCookie(string baseCookie, UserAuthData data, string cookieName)
        {
            HttpCookie cLogin = new HttpCookie(baseCookie);

            #if ! DEBUG && !PAYMENT_DEBUG
            cLogin.Domain = COOKIE_DOMAIN;
            #endif

            #region -- login data

            string oData = data.ToCookieValue();
            string vData = new ebay.security.auth.CCrypto().Encode(oData, 1);

            cLogin.Values.Add(cookieName, HttpUtility.UrlEncode(vData));

            #endregion

            #region -- hmac

            string vHmac = ebay.security.Hmac.Instance.GetHash(oData);

            cLogin.Values.Add(COOKIE_SUB_AUTH_HMAC, HttpUtility.UrlEncode(vHmac));

            #endregion

            return cLogin;
        }
示例#4
0
 public static void ExtendLoginExpiry(UserAuthData data)
 {
     HttpContext.Current.Response.Cookies.Set(MakeAuthCookie(COOKIE_NAME_AUTH, data, COOKIE_SUB_LOGIN_INFO));
 }
示例#5
0
        private static UserAuthData GetLoginCookieData(string baseCookie, string cookieName)
        {
            UserAuthData data = new UserAuthData();

            HttpCookie cLogin = HttpContext.Current.Request.Cookies[baseCookie];

            if (null != cLogin)
            {
                string cData = cLogin.Values[cookieName];
                string cHmac = cLogin.Values[COOKIE_SUB_AUTH_HMAC];

                if (false == string.IsNullOrEmpty(cData) && false == string.IsNullOrEmpty(cHmac))
                {
                    string oData = HttpUtility.UrlDecode(cData);
                    string oHmac = HttpUtility.UrlDecode(cHmac);

                    string vData = new ebay.security.auth.CCrypto().Decode(oData, 1);

                    if (false == string.IsNullOrEmpty(vData))
                    {
                        if (true == ebay.security.Hmac.Instance.CompareHash(vData, oHmac))
                        {

                            SortedList<string, string> parts = ParseUrlParams(vData);

                            if (null != parts && 0 < parts.Count)
                            {
                                data.UserId = (true == parts.ContainsKey(@"a")) ? parts[@"a"] : string.Empty;
                                data.RemoteAddress = (true == parts.ContainsKey(@"b")) ? parts[@"b"] : string.Empty;

                                if (true == parts.ContainsKey(@"c"))
                                {
                                    long lat = 0;

                                    data.LastAccessed = (true == long.TryParse(parts[@"c"], out lat)) ? new DateTime(lat) : DateTime.MinValue;
                                }
                            }
                        }
                    }
                }
            }

            return data;
        }