© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
stayclaxxy

❔ Calling an Azure AD protected Web API endpoint from an Azure AD protected Web App [.NET 7]

I am having trouble getting the correct flow/configuration to call my Web API Endpoint that is protected with Azure AD.

This is how the Authentication is configured on the web API currently:
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration, "AzureAd");
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration, "AzureAd");

The Configuration just has the details like clientId, TenantId, Domain, Audience and secret, etc.


This is how I am setting up authentication on the web app: (the only scope is an expose API from the API App registration named "WeatherForecast")
string[] initialScopes = new[] { "api://33..38/WeatherForecast" };

// Add services to the container.
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration)
    .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
    .AddInMemoryTokenCaches();
string[] initialScopes = new[] { "api://33..38/WeatherForecast" };

// Add services to the container.
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration)
    .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
    .AddInMemoryTokenCaches();


My question is, how do I get the access token to add to the authorization header to call my web api endpoint? The endpoints are role-based based on the user's roles, so is On-Behalf-Of flow the correct flow to use here? If so, I have looked at Microsoft's examples, and I am still very confused on how to achieve what I want to do. TIA!
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Validate an Azure ad token in .net 7
C#CC# / help
3y ago
Can anybody help on how to implement Azure AD Authentication in ASP.NET web app(.NET Framework)?
C#CC# / help
3y ago
trying to plan validating azure ad token and calling graph api in azure function
C#CC# / help
2y ago
asp - Calling another api endpoint
C#CC# / help
2y ago