示例#1
0
        bool AuthorizeSession(HttpContext context)
        {
            string sessionIdParam = GetSessionIdParam(context);
            string antiCsrfParam  = GetAntiCsrfParam(context);

            if (!String.IsNullOrEmpty(antiCsrfParam) && !String.IsNullOrEmpty(sessionIdParam))
            {
                var d = this._cache.Get <ConcurrentDictionary <string, string> > (sessionIdParam);
                if (d != null)
                {
                    string accessToken = "";
                    if (d.ContainsKey(antiCsrfParam))
                    {
                        accessToken = d[antiCsrfParam];
                    }
                    if (accessToken != "")
                    {
                        this._cache.Set <string>(antiCsrfParam, accessToken);

                        // Информация о владельце
                        _userInfo = this._cache.Get <OAuthUserInfo>(accessToken);
                        if (_userInfo == null)
                        {
                            _userInfo = GetUserInfo(this._options.AuthenticationEndpoint, accessToken);
                            this._cache.Set <OAuthUserInfo>(accessToken, _userInfo, new TimeSpan(1, 0, 0));
                        }
                        CreateAuthTicket(context, accessToken);

                        string i;
                        d.TryRemove(antiCsrfParam, out i);
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#2
0
        bool AcceptTicket(HttpContext context)
        {
            string antiCsrfParam = GetAntiCsrfParam(context);
            string sid           = context.Request.Cookies[string.Concat(antiCsrfParam, "abc123")] != null ? context.Request.Cookies[string.Concat(antiCsrfParam, "abc123")] : "";

            if (!String.IsNullOrEmpty(antiCsrfParam) && sid.Length > antiCsrfParam.Length)
            {
                string add = this._options.ResourceServerSecret;
                if (String.IsNullOrEmpty(add))
                {
                    add = context.Request.Host.Value;
                }
                string accessToken = HexString.XOR(sid, add + antiCsrfParam);
                // Информация о владельце
                _userInfo = this._cache.Get <OAuthUserInfo>(accessToken);
                if (_userInfo == null)
                {
                    _userInfo = GetUserInfo(this._options.AuthenticationEndpoint, accessToken);
                    this._cache.Set <OAuthUserInfo>(accessToken, _userInfo, new TimeSpan(1, 0, 0));
                }
                return(true);
            }
            return(false);
        }