Unable to get UI to call API when using separate registered apps

Lange Gregory 20 Reputation points
2023-08-24T13:39:13.99+00:00

I have been trying for weeks to get my UI to be able to call my api. I have followed the standard of one app registration per application and exposed a scope on my API registration. When using IDownstreamAPI helper to call the api i only ever get Unauthorized. If i try to not use the helper class and build it myself per the examples then i says it cannot pull back my token. My UI app has been given admin consent for the tenet i need it on and the API app doesn't have any api permissions needed so i wouldn't think it would need consent also. As a point of reference i have been following https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-access-web-apis to try and get my solution working with not success.

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

Accepted answer
  1. Akshay-MSFT 17,951 Reputation points Microsoft Employee Moderator
    2023-08-25T08:12:39.3033333+00:00

    @Lange Gregory

    Kindly share the screenshot or full error message after (removing PII) you are getting while trying to call the API from UI app.

    Update1:

    Looks to be a scope relate issue while calling the API. Kindly ensure your app have appropriate scope to get an access token. For ref you may follow : Angular single-page application using MSAL Angular to authenticate users with Azure AD for Customers and call a protected ASP.NET Core web API

    Update 2:

    Below are the things OP changed based off looking at the sample project.

    Program.cs (API)

    app.MapControllers();

    to

    app.UseEndpoints(endpoints => {

    _ = endpoints.MapControllers();

    });

    On the controller in question that is calling the IDownstream helper i had to add: [AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]

    Thanks,

    Akshay Kaushik

    0 comments No comments

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.