0

I have an azure active directory B2C account. The client and web api of the application are registered there. There are also user flows, for example, for registration and login. A web api (asp net core web api) protected by a b2c token. How to implement the logic in which after the user logs in to the system the web API application can validate the b2c token and exchange it for its own token, with the claims I need. Or maybe you can immediately add your custom claims to the b2c token? Provided that claims are stored in a database on their own server.

Studied a bunch of documentation from Microsoft. The first thing I discovered was the use of api connectors. https://learn.microsoft.com/en-us/azure/active-directory-b2c/add-api-connector-token-enrichment?pivots=b2c-user-flow Maybe this is my decision? But I didn't understand how to check this locally from localhost.

Please share the best practices for writing such logic.

1 Answers1

0

As per your link, you need to use custom policies.

In the link, you see e.g. "balance" (a custom claim) returned from the API call and added to the JWT for the RelyingParty.

You don't need to convert tokens - just call the API.

There are a number of options to secure your API.

You can return error messages.

rbrayb
  • 46,440
  • 34
  • 114
  • 174
  • @rbraub Thanks for the answer. Is it possible to implement an example with a balance, but through a user flow? I only need to add one custom claim to the b2c token. And the logic with custom policies looks overwhelming and complicated for that. I tried according to the documentation but ran into a problem. More info here: [link](https://stackoverflow.com/questions/69562819/how-to-enrich-azure-b2c-token-with-custom-claims-using-api-connectors-and-asp-ne) – Александр Климук Oct 14 '21 at 12:31
  • I may be researching the wrong direction, correct me if possible – Александр Климук Oct 14 '21 at 12:57
  • Indeed you can - https://learn.microsoft.com/en-us/azure/active-directory-b2c/user-flow-custom-attributes?pivots=b2c-user-flow – rbrayb Oct 14 '21 at 18:56