Adding Permissions to Claims - Microsoft.Identity.Web & B2C

234 views Asked by At

I'd like to ask for advice or direction to any article/documentation on how to add custom claims to user identity. Project I am working on is using Azure B2C with Microsoft.Identity.Web.

I am searching for a robust way of adding a custom claim during web request in an web app. The claim would contain permissions obtained from an application database. So I also need a way to store that claim between requests, so I don't trip to database on every request.

The model of roles and permissions stored in the database is quite complex and dynamic (managed by admins), thus simple storing custom claim in B2C via graph API is an option.

I was thinking about stepping in with a middleware doing claims transformation:

  • Is this ok with Microsoft.Identity.Web or is it something that I shouldn't do?

  • Still not sure how to persist the claim between requests - is there any robust way while using Microsoft.Identity.Web?

1

There are 1 answers

1
wojtekdo On

If you want to have permissions in the token, and I presume that would be the optimal way, then I'd go with saving those in the user object as a Base64 encoded JSON for example. You can have quite complex structure which AAD B2C would just return in the token for the user. Then you may do what you want with this value in once it hits your API. It's in the token so it's properly signed and you get the token with every request so you don't think about reaching to any database.