Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis
Created February 24, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdyrrahitis/5d87b46845263c7480a57ac8419361c3 to your computer and use it in GitHub Desktop.
Save gdyrrahitis/5d87b46845263c7480a57ac8419361c3 to your computer and use it in GitHub Desktop.
private async Task LoginAsync(User user)
{
var properties = new AuthenticationProperties
{
AllowRefresh = false,
IsPersistent = true,
ExpiresUtc = DateTimeOffset.UtcNow.AddSeconds(10)
};
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
new Claim(ClaimTypes.Name, user.UserName),
new Claim(ClaimTypes.GivenName, user.FirstName),
new Claim(ClaimTypes.Surname, user.LastName),
new Claim(ClaimTypes.DateOfBirth, user.DateOfBirth.ToString("o"), ClaimValueTypes.DateTime)
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(principal, properties);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment