Azure B2C not generating a scope for API in JWT

Andrew Fraser 136 Reputation points
2025-01-28T16:02:49.8533333+00:00

I am following this series of videos:

https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbFdGUFd2eGstZ3dVUHRBbzJrcjZBQkxKTndtQXxBQ3Jtc0tuT3NvVGk4U21qeUsxSER1M2RaTVNNU1MzSlRJZUdfUnNNQmt6ejI0T20zTmhaOU5ZaTYtS3p5NUFxdjI4VzhuQnltWFpxczlRNGJzaVBvbHJpRVROZVM0dlBmczAxVFZaLTRjYkdVVzlfVm5VS3RwZw&q=https%3A%2F%2Faka.ms%2Fdotnet%2Fbeginnervideos%2Fyoutube%2Fazure&v=hIP5F1bvs5s

Specifically [4 of 8] where Matt configures B2C to generate a scope that will be passed to a WebAPI.

I have a fully functioning API (when the end points are not marked as Authorize) however, when I follow all his steps, I get a 401 (Not Authorized) error when trying to hit an endpoint on my API.

When I run the login user flow, I note that there is no "scp" entry in the generated JWT.

Interestingly, Matt conveniently skips over this when demonstrating the generated token in the video.

Can someone explain what I need to do to get my API to accept the authenticated user API endpoint requests?

Andy

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,257 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,138 questions
{count} votes

Accepted answer
  1. Sakshi Devkante 575 Reputation points Microsoft Vendor
    2025-02-05T15:24:37.5433333+00:00

    Hello @Andrew Fraser

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer. 

    Issue: Azure B2C not generating a scope for API in JWT

    Solution: Resolved by @Andrew Fraser by following the below steps

    YouTube video explaining the steps and code required to get the API authentication working. For those struggling with Matt's video, check this one out https://www.youtube.com/watch?v=gxPWRq9BteI this video helps in configuring Azure AD B2C authentication for a web app and web API.

    Best regards,
    Sakshi Devkante

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andrew Fraser 136 Reputation points
    2025-02-03T17:16:52.51+00:00

    I have almost given up on this until I found a much better YouTube video explaining the steps and code required to get the API authentication working. For those struggling with Matt's video, check this one out https://www.youtube.com/watch?v=gxPWRq9BteI.

    Andy

    0 comments No comments

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.