Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request.GetOwinContext().Authentication.SignIn not creating cookie

The following Code is not creating .ASPNET Cookie, I am using this code in WebAPI custom login method

  //TODO Validate Credential
  var claims = new List<Claim>();
            claims.Add(new Claim(ClaimTypes.Name, "ABCDE"));
            claims.Add(new Claim(ClaimTypes.Email, "[email protected]"));

            var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            var authmgr = Request.GetOwinContext().Authentication;
            authmgr.SignIn(id);
like image 239
NSS Avatar asked Feb 02 '14 21:02

NSS


People also ask

How to configure Cookie authentication in OWIN?

When the OWIN runtime fires up, it looks via Reflection for a class named Startup class with a Configuration (IAppBuilder app) method and when it finds it executes that method. ConfigureAuth () then configures Cookie Authentication for local logins and the external providers for Google, Twitter and Github.

How do I use Cookie authentication in Okta?

To use cookie authentication, you need to state that as your intention plus set the default authentication type: To add the authentication middleware, Okta have made it really easy by adding an extension method specifically to the IAppBuilder instance, that you call with predefined options:

What is the Authentication Manager in OWIN formsauthentication?

If you’ve used FormsAuthentication in ASP.NET you know that there’s a global object that handles management of the user tracking cookie that associates a user with an account. OWIN has its own version of an authentication manager in the IAuthenticationManager interface which is attached to the HttpContext object.

How to create MVC application with no authentication in Visual Studio?

First, create a new project in Visual Studio of type ASP.NET Web Application (.NET Framework). Name it whatever you want and on the next screen select the MVC template with No Authentication. Note: Okta also works great with Web API; if you’d like to read more on this topic there’s another great blog post about it.


1 Answers

Did you make sure you added the following to your App_Start/Startup.Auth.cs ?

public void ConfigureAuth(IAppBuilder app)
{
   app.UseCookieAuthentication(new CookieAuthenticationOptions
   {
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
      LoginPath = new PathString("/Account/Login")
   });
}

Check out Brock Allen's primer -

http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/

like image 87
ecco88 Avatar answered Sep 17 '22 18:09

ecco88