How to update a claim when using Session Authentication Module (SAM)

寵の児 提交于 2019-12-10 20:32:16

问题


I'm using the Session Authentication Module to store the user claims in the authentication cookie.

What is the recommended approach to update the user's claims whilst they are logged in? An example would be if they update their profile (First Name/Last Name) and we want to update the associated claims.

I don't want to log the user out when this happens so DeleteSessionTokenCookie is not an option.


回答1:


Set a new session cookie with SAM.WriteSessionTokenToCookie.




回答2:


Leastprivilege's answer is correct.

But in response to Vijay V's comment, here's example code on how to update the cookie after adding new claims to your claims principal:

var sam = FederatedAuthentication.SessionAuthenticationModule;
if (sam != null)
{
    var token = new SessionSecurityToken(claimsPrincipal);
    sam.WriteSessionTokenToCookie(token);
}  

Pulled the code from here.



来源:https://stackoverflow.com/questions/15157841/how-to-update-a-claim-when-using-session-authentication-module-sam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!