title: Update a claim in an ASP.NET Core 2.1 Authentication Cookie
body: <p>How do I update a claim value in an ASP.NET Core 2.1 Authentication Cookie?</p>
  
  <p>Little bit of context to my question: </p>
  
  <p>I have an dotnet Core 2.1 MVC project that is using Cookie authentication.</p>
  
  <p>The web site gets most of it's data from a API that uses bearer tokens to authenticate.  The bearer tokens are fairly short lived and the API also returns a refresh token to get a new bearer token.  </p>
  
  <p>When the user logs in I get a token from the API and store it as a claim in the auth cookie, like so:</p>
  
  <pre><code>var props = new AuthenticationProperties{  ...  };
  
  var claims = new[]
  {
      new Claim("ApiAccessToken", apiToken.AccessToken),
      new Claim("ApiRefreshToken", apiToken.RefreshToken),
      // other claims ...
  };
  
  var identity = new ClaimsIdentity(claims, 
      CookieAuthenticationDefaults.AuthenticationScheme);
  
  await Request.HttpContext.SignInAsync(
      CookieAuthenticationDefaults.AuthenticationScheme,
      new ClaimsPrincipal(identity), props);
  </code></pre>
  
  <p>I'm using Polly to ensure authentication before making calls to the API, if the first try to the API gets a 401, I use the refresh token to get a new bearer token. I want to update the ApiAccessToken and ApiRefreshToken claims in the auth cookie with these new values.</p>
  
  <hr>
  
  <p>Or is there a altogether better way to handle this scenario?</p>
  
  <p>Thanks.</p>