Adding Claims to MemberIdentityUser.Claims - gets cleared after SignInAsync.
Hi!
I am authenticating credentials against an external API and if successful I'm creating a MemberIdentityUser()-object that I sign in with the _memberSignInManagaer. And adding roles work correctly.
But as soon as I try to add Claims on the MemberIdentifyUser-object, they are cleared. When iterating the claims on an razor page for example (for debugging purpose) they are not there. Why is that so?
var member = new MemberIdentityUser();
member.Email = Entity.Email;
member.Name = Entity.Name;
member.UserName = Entity.UserName;
//Add member role as default.
member.AddRole(memberRole);
if (Entity.HasGradeAccess)
{
member.AddRole(chairmanRole);
}
//Sign in with lime integrated user.
await _memberSignInManager.SignInAsync(member, true);
Okay. It seems that you can actually add Claims in the above code... Then you have to implement an class, for example "AdditionalUserClaimsPrincipalFactory", that inherits from UserClaimsPrincipalFactory
So you could do then re-add the claims added previously in this code below and they will persist until signing out.
Hi Joel - was this still the solution you ended up going with? I don't want to set extra Claims as such but the groups the member belongs to, but can't find documentation on how to do that.
Adding Claims to MemberIdentityUser.Claims - gets cleared after SignInAsync.
Hi! I am authenticating credentials against an external API and if successful I'm creating a MemberIdentityUser()-object that I sign in with the _memberSignInManagaer. And adding roles work correctly.
But as soon as I try to add Claims on the MemberIdentifyUser-object, they are cleared. When iterating the claims on an razor page for example (for debugging purpose) they are not there. Why is that so?
Okay. It seems that you can actually add Claims in the above code... Then you have to implement an class, for example "AdditionalUserClaimsPrincipalFactory", that inherits from UserClaimsPrincipalFactory
So you could do then re-add the claims added previously in this code below and they will persist until signing out.
Code is from this link in similar post on umbraco forum: https://our.umbraco.com/forum/using-umbraco-and-getting-started/108270-how-to-add-custom-claim-to-the-loggedin-member-in-umbraco-9
Hi Joel - was this still the solution you ended up going with? I don't want to set extra Claims as such but the groups the member belongs to, but can't find documentation on how to do that.
thanks
Andrew
@andrew shearer This video might give you some hints on how to do it: https://youtu.be/aouFfym_7Zs
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.