What is HttpContext.SignInAsync() signing in against?

Viewed 444

What does HttpContext.SignInAsync() do? I call it, but nothing gets changed in my httpcontext. When I get a new request from a user with a cookie it still has anonymous user. I'm not sure if anything is failing or how to check.

This is how I'm currently setting the user cookie and calling HttpContext.SignInAsync()

        private async void AddUserCookie(AuthRequest authRequest)
        {
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, authRequest.UserName),
                new Claim(ClaimTypes.Name, authRequest.UserName),
                new Claim(ClaimTypes.Email, "TestClaim@Test.com")
            };

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

            var authProperties = new AuthenticationProperties
            {
                AllowRefresh = true,
                ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1),
                IsPersistent = true,
                IssuedUtc = DateTimeOffset.UtcNow,
            };

            await this._httpContextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties).ConfigureAwait(false);

I would just like some clarification on what is happening behind the scenes. I tried looking through the source code, but it didn't make a lot of sense.

1 Answers

in stratup.configure check

app.UseAuthentication();
app.UseAuthorization();
Related