Skip to content

Instantly share code, notes, and snippets.

@mclasson
Created August 3, 2017 13:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mclasson/6c1ba5b4843907f338b0bf1e4302a541 to your computer and use it in GitHub Desktop.
public async Task<IActionResult> Index()
{
var principal = User.Identity as ClaimsIdentity;
var idClaim = principal.Claims.Where(i => i.Type == "http://marcusclasson.com/claims/id")
.SingleOrDefault();
if(idClaim == null)
{
principal.AddClaim(new Claim("http://marcusclasson.com/claims/id", "MyCustomId"));
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignInAsync(User);
}
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment