Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the namespace for Context.Response.SignIn() using ASP.NET 5 Cookie Authentication

Tags:

asp.net-core

We're adding cookie authentication to a fresh ASP.NET 5 application. (currently using Beta 7)

We added this to Startup.cs:

//Use cookie authentication
app.UseCookieAuthentication(options => {
    options.LoginPath = new PathString("/Login");
    options.AutomaticAuthentication = true;
});

And the [Authorize] attribute is working fine, redirecting to the login page.

Inside our Login() controller method, we're creating claims and an identity:

var claims = new List<Claim>();
claims.Add(new Claim("name", loginRequest.Username));

var identity = new ClaimsIdentity(claims.ToArray(),
    CookieAuthenticationDefaults.AuthenticationScheme);

As the last step, we're trying to call the SignIn() method.

Context.Response.SignIn(identity); //what is the namespace for SignIn()??

But we can't find the namespace for the SignIn() method. Our goal is use the simplest possible solution without the full Identity framework. (although I'm okay with referencing it if necessary to get the SignIn() plumbing to work.)

What is the namespace for the SignIn() method mentioned in the documentation?

like image 763
Ender2050 Avatar asked Sep 08 '15 17:09

Ender2050


1 Answers

I figured it out - looks like I was using some out of date documentation. I should have been calling SignIn() like this:

await Context.Authentication.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme, 
    new ClaimsPrincipal(identity));

This article and the simplified example he created was incredibly helpful. Thanks!

like image 100
Ender2050 Avatar answered Sep 28 '22 08:09

Ender2050