3

I am writing simple REST service for leaning vNext and new MVC. I want to understand how to create a simple OWIN authorization with custom logic. For example, imagine that a service has just a simple in-memory list of tokens and I want to check that a request contains token that exist in that list.

If I understood properly, I just need to override AuthorizeAttribute class, but I cannot find how to do this in the right way.

public class CustomAuthorize : AuthorizeAttribute
{
    public override Task OnAuthorizationAsync(AuthorizationContext context)
    {
        return base.OnAuthorizationAsync(context);
    }
}

If I misunderstood this, could you please explain what classes I need to use and can I do it.

1 Answer 1

4

You can use :

public class AuthorizeClass: ActionFilterAttribute
    {
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (context.HttpContext.Session["token"] == null || context.HttpContext.Session["user"] == null)
            {
                context.HttpContext.Response.Redirect("/login");
            }
            await next();
        }

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.