title: Update Identity User Claims in Web API
body: <p>I'm currently trying to update the user's email/username from a mobile app to a Web API project. I'm currently using oauth and token authentication. When updating the identity user, the user becomes unauthenticated because the username and access token are no longer valid. From what I have read, I must update the identity claims. This is what I have tried so far:</p>
  
  <pre><code>var identity = new ClaimsIdentity(User.Identity);
  
  if (result)
  {
      var identityUser =  await UserManager.FindByNameAsync(User.Identity.Name);
  
      identityUser.Email = AntiXssEncoder.HtmlEncode(value.Email, true);
      identityUser.UserName = AntiXssEncoder.HtmlEncode(value.Email, true);
  
      var identityResult = await UserManager.UpdateAsync(identityUser);
  
      if(identityResult.Succeeded)
      {
          var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
  
          await UserManager.RemoveClaimAsync(identityUser.Id, identity.FindFirst(ClaimTypes.Name));
          await UserManager.AddClaimAsync(identityUser.Id, new Claim(ClaimTypes.Name, value.Email));
  
          identity.RemoveClaim(identity.FindFirst(ClaimTypes.Name));
          identity.AddClaim(new Claim(ClaimTypes.Name, value.Email));
  
          authenticationManager.AuthenticationResponseGrant =
                      new AuthenticationResponseGrant(
                      new ClaimsPrincipal(identity),
                      new AuthenticationProperties { IsPersistent = false });
       }
    return Ok();
  }
  </code></pre>
  
  <p>However, it still shows the previous email when using <code>User.Identity.Name</code> and the claims for the user within the <code>authenticationManager</code> have not been updated either. I'm not sure what else to do as there isn't much documentation on this for Web API. Any help is greatly appreciated. </p>