Restricting Access to Azure AD B2C API

hampton123 1,175 Reputation points
2023-08-03T21:05:37.42+00:00

Hi, I have a web app where users sign in using B2C, and then they call my company's API. As it stands right now, anyone can make an account and log in to access our API. I want my company to be able to see their account, grant the user access, and then the user can call the API. Is there a way that we could restrict access to users, and only allow them to call the API if we authenticate them first?

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Krzyczkowski 491 Reputation points MVP
    2023-08-05T06:32:34.38+00:00

    Hi,

    The solution you are looking for is not about authentication but authorization.

    If I understood correctly, in your solution you have web application secured by the Azure AD B2C. Once the user is authenticated, B2C issues access token which can be used to access your API, correct?

    In this case if you want to restrict the access to the Web API only to specific users, you will need to implement authorization mechanism.

    You have basically two options here:

    1. In the access token that is used with your Web API you will add additional claim, like "Role" or "UserType" and than on the Web API side you will validate whether the token has this claim or not. Basing on that you decide whether API returns data or return HTTP 403 status Forbidden.
    2. You implement authorization on the Web API side fully. It means that you do a verification on the Web API side using user's object ID against authorization system/database to see if this specific user has permission to access your Web API's specific endpoint. It is more complex solution.

    Here is the fragment of my video which describes both approaches:
    https://youtu.be/sE6fnagYp1M?t=358


0 additional answers

Sort by: Most helpful

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.