-
Notifications
You must be signed in to change notification settings - Fork 218
adding call api to web app
To call a web API from your web app that signs-in users or your protected web API, you need to add a few lines:
- in the configuration file
- in Startup.cs
- in the controller
When you use Microsoft.Identity.Web, you have three usage options for calling an API:
- Option 1: Call Microsoft Graph with the Microsoft Graph SDK's
GraphServiceClient
- Option 2: Call an Azure SDK using the Azure with
TokenAcquisitionTokenCredential
- Option 3: Call a downstream web API with the helper class
IDownstreamWebApi
- Option 4: Call a downstream web API without the helper class, acquiring a token yourself with
ITokenAcquisition
See A web app/API that calls web APIs: Code configuration to see what to change in the configuration file, and startup.cs. See also Using client certificates if you want to use certificates instead of client secrests to authenticate your web app/API.
See A web app/API that calls web APIs: Call a web API for the changes to make in the controller.
See Calling Graph to learn how to specify delegated scopes or app permissions, specify a tenant, and or authentication scheme using .WithScopes
, .WithScopes(scopes)
, .WithAppOnly(bool, tenantId), and .WithAuthenticationScheme(authenticationScheme)
When using IDownstreamWebApi, you can override the Http headers by using the
string response = await _downstreamWebApi.GetForUser<string>("DownstreamAPI",
options => {
options.RelativePath = "me";
options.CustomizeHttpRequestMessage = message =>
{
var headers = message.Headers;
// Do what you want to change the HttpHeaders.
// The Authorization header is already populated when the delegate is called
};
});
- Home
- Why use Microsoft Identity Web?
- Web apps
- Web APIs
- Using certificates
- Minimal support for .NET FW Classic
- Logging
- Azure AD B2C limitations
- Samples
- Web apps
- Web app samples
- Web app template
- Call an API from a web app
- Managing incremental consent and conditional access
- Web app troubleshooting
- Deploy to App Services Linux containers or with proxies
- SameSite cookies
- Hybrid SPA
- Web APIs
- Web API samples
- Web API template
- Call an API from a web API
- Token Decryption
- Web API troubleshooting
- web API protected by ACLs instead of app roles
- gRPC apps
- Azure Functions
- Long running processes in web APIs
- Authorization policies
- Generic API
- Customization
- Logging
- Calling graph with specific scopes/tenant
- Multiple Authentication Schemes
- Utility classes
- Setting FIC+MSI
- Mixing web app and web API
- Deploying to Azure App Services
- Azure AD B2C issuer claim support
- Performance
- specify Microsoft Graph scopes and app-permissions
- Integrate with Azure App Services authentication
- Ajax calls and incremental consent and conditional access
- Back channel proxys
- Client capabilities