Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to login page with OWIN

I'm using OWIN to authenticate with Facebook per: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

I want to be able to redirect to a specific login page when a user attempts to visit a page while they are unauthenticated.

As it stands, when I decorate an action with [Authorize], I get a 401 error from IIS.

If I was using Forms authentication, I would have this in my web.config:

<authentication>
  <forms loginUrl="~/Account/Login" timeout="2880" />      
</authentication>

Is there something similar I can do with OWIN, or do I need to create a custom Authorize attribute?

like image 780
Mister Epic Avatar asked Jan 12 '14 19:01

Mister Epic


1 Answers

You can configure the login page when you are configuring the cookie authentication:

        app.UseCookieAuthentication(new CookieAuthenticationOptions {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
like image 189
Hao Kung Avatar answered Oct 21 '22 15:10

Hao Kung