Extending Azure AD B2C with Custom Role Management and Token Handling in Microservices

ii42-8206 20 Reputation points
2023-12-01T07:10:30.3366667+00:00

Hi,

I am currently developing a microservice-based application (controlling both, the front- and backend) with Azure AD B2C as a user authentication solution. My focus is on extending the capability to manage custom user roles and permissions within the microservice system, separate from the identity management provided by Azure AD B2C, since management of custom user roles is not supported.

I would appreciate your guidance on a few specific points:

  1. Token Management: Would it be beneficial to include role information from the service that handles the role management in Azure AD B2C tokens (ID and/or Access Tokens) for quicker role-based access control in our application? And is it possible to add the roles of the specific user in custom claims not just to ID-Token during sign-in but also to the Access Token? My understanding is that customization options are primarily for the sign-in process and claims in ID Tokens, while Access Tokens mainly contain application scope and subject information, but can't get information from external sources, like the roles service. I am asking, since treating a ID-Token like a access token (if the roles where included) seems a bit odd to me.
  2. Refresh Token Revocation: Is it possible to revoke refresh tokens in Azure AD B2C? The documentation seems to provide limited information about this but mentions something about sessions.

I am also evaluating whether Azure AD B2C's capabilities are sufficient for complex role-based access control (RBAC) and fine-grained permission management for complex custom business logic. Please correct me if my understanding is not aligned with the platform's functionalities.

It seems like the client id within the OIDC scope, like stated in the documentation, could be used for something like this.

Afaik this is not a part of the Open ID standard but rather a Microsoft custom extension on top? Am I correct in this assumption?

Thanks for your help!

Microsoft Security Microsoft Entra Microsoft Entra External ID
Microsoft Security Microsoft Entra Other
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 37,206 Reputation points Microsoft Employee Moderator
    2023-12-01T23:41:16.38+00:00

    Hi ii42-8206,

    You cannot use RBAC out-of-the-box with Azure AD B2C. The roles would need to be assigned within the B2C's AAD directory or hosted externally and retrieved via Graph API, or if you are using ROPC you would still have to make a call to the underlying AAD and only Microsoft accounts (and not social identities) would be supported. Azure AD B2C does not support out-of-box support for role claims for consumer accounts as it would not be feasible for the admin to assign the role to consumer identities.

    You can use custom claims in to allow consumers to select the required role during the signup process which is returned in the token as well. https://learn.microsoft.com/en-us/aspnet/core/security/authentication/claims?view=aspnetcore-7.0

    You could also leverage Custom Policies, which allow you to call a REST API during authentication. This can be used to pass the ObjectId of the user to your API and return the roles to Azure AD B2C. B2C can then issue the roles as a claim into the token.

    https://learn.microsoft.com/en-us/azure/active-directory-b2c/add-api-connector-token-enrichment?pivots=b2c-custom-policy

    2.You can revoke refresh tokens by these methods:

    I'm not sure I fully understand your question about client ID, so feel free to clarify. But this parameter applies not only to Microsoft but is used by other identitiy providers too. For example, an id_token value received from Google would need match the value of the --oidc-client-id parameter.

    Let me know if this helps at all and if you have further questions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.