예제 #1
0
        public JWTUser RequireAuthentication(HttpRequest request)
        {
            JWTUser result;

            if (!string.IsNullOrEmpty(request.Headers["Authorization"]))
            {
                result = JWT.DecodeToken(GetAuthParam(request.Headers["Authorization"]));
            }
            else
            {
                var cookies = request.Cookies;
                if (cookies == null)
                {
                    throw new SecurityException("Unable to find cookie");
                }


                var cookie = cookies["fso"];
                if (string.IsNullOrEmpty(cookie))
                {
                    throw new SecurityException("Unable to find cookie");
                }
                result = JWT.DecodeToken(cookie);
            }
            if (result == null)
            {
                throw new SecurityException("Invalid token");
            }

            return(result);
        }
예제 #2
0
파일: Api.cs 프로젝트: fourks/FreeSO
        public JWTUser RequireAuthentication(HttpRequestMessage request)
        {
            /*var http = HttpContext.Current;
             * if (http == null)
             * {
             *  throw new SecurityException("Unable to get http context");
             * }*/

            var cookies = request.Headers.GetCookies().FirstOrDefault();

            if (cookies == null)
            {
                throw new SecurityException("Unable to find cookie");
            }


            var cookie = cookies["fso"];

            if (cookie == null)
            {
                throw new SecurityException("Unable to find cookie");
            }

            var result = JWT.DecodeToken(cookie.Value);

            if (result == null)
            {
                throw new SecurityException("Invalid token");
            }

            return(result);
        }