c# - Update claims in ClaimsPrincipal -
i using adal azure active directory , need add claims via custom owinmiddleware. when add claims principal, able access them in current request. after page refresh, claim gone.
i thought owin handled serialization of claims , put cookie itself, doesn't seem case.
i add claims follows:
var claimsidentity = (claimsidentity) claimsprincipal.current.identity; if (!claimsidentity.isauthenticated) return; var identity = new claimsidentity(claimsidentity); var currenttenantclaim = gettenantclaim(); if (currenttenantclaim != null) claimsidentity.removeclaim(currenttenantclaim); claimsidentity.addclaim(new claim(claimtypes.currenttenantid, id)); context.authentication.authenticationresponsegrant = new authenticationresponsegrant (new claimsprincipal(identity), new authenticationproperties {ispersistent = true});
any ideas on how persist new claims cookie?
i've added claims wrong identity. had added identity variable instead of claimsidentity.
working code:
var claimsidentity = (claimsidentity) context.authentication.user.identity; if (!claimsidentity.isauthenticated) return; var identity = new claimsidentity(claimsidentity); var currenttenantclaim = gettenantclaim(identity); if (currenttenantclaim != null) identity.removeclaim(currenttenantclaim); identity.addclaim(new claim(claimtypes.currenttenantid, id)); context.authentication.authenticationresponsegrant = new authenticationresponsegrant (new claimsprincipal(identity), new authenticationproperties {ispersistent = true});
Comments
Post a Comment