Search code examples
c#claims

How to add a Claim to a SystemUser as a flag(bool) in C#


I need to add a Claim to be passed to the front-end. I want to check "IsSystemUser" of type bool and then value of the bool of course so users are not able to see system settings.

I am using this:

        context.IssuedClaims.Add(new Claim("IsSystemUser", ));

However, I noticed that it has string Type, string Value and/or string ValueType.

The IntentUser already has a field isSystemUser, I just don't know how to add claim to it.

        context.IssuedClaims.Add(new Claim("IsSystemUser", user.IsSystemUser.ToString()));

Is that how I should do it?


Solution

  • Claims always have a string value (you can read more here). There is a possibility to specify valueType as Boolean:

    
    context.IssuedClaims.Add(new Claim("IsSystemUser", user.IsSystemUser.ToString(),
                              ClaimValueTypes.Boolean));
    

    However, on the front-end, you have to parse it manually from string.