public void OnAuthorization(AuthorizationFilterContext context)
        {
            var token = context.HttpContext.Request.Headers["Authorization"];

            if (String.IsNullOrEmpty(token))
            {
                context.Result = new ContentResult()
                {
                    StatusCode = 401,
                    Content    = "No token provided"
                };
            }
            else
            {
                if (!sessions.IsCorrectToken(token))
                {
                    context.Result = new ContentResult()
                    {
                        StatusCode = 403,
                        Content    = "Not authorized"
                    };
                }
            }
        }
Esempio n. 2
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            string token = context.HttpContext.Request.Headers["Authorization"];

            if (String.IsNullOrEmpty(token))
            {
                context.Result = new ContentResult()
                {
                    StatusCode = 401,
                    Content    = "Access not authorized."
                };
            }
            else
            {
                if (!sessions.IsCorrectToken(token.ToLower()))
                {
                    context.Result = new ContentResult()
                    {
                        StatusCode = 403,
                        Content    = "Forbidden."
                    };
                }
            }
        }
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            string headerToken = context.HttpContext.Request.Headers["Authorization"];

            if (string.IsNullOrEmpty(headerToken))
            {
                context.Result = new ContentResult()
                {
                    StatusCode = 401,
                    Content    = "Administrador no logeado."
                };
            }
            else
            {
                try
                {
                    Guid token = Guid.Parse(headerToken);
                    if (!sessions.IsCorrectToken(token))
                    {
                        context.Result = new ContentResult()
                        {
                            StatusCode = 403,
                            Content    = "Token invalido."
                        };
                    }
                }
                catch (FormatException)
                {
                    context.Result = new ContentResult()
                    {
                        StatusCode = 401,
                        Content    = "Formato invalido de token"
                    };
                }
            }
        }