-
Notifications
You must be signed in to change notification settings - Fork 217
existing web app
Jean-Marc Prieur edited this page Oct 28, 2024
·
4 revisions
-
Add an
"AzureAd"
section in the appsettings.json:{ "AzureAd" : { "Instance" : "https://login.microsoftonline.com", "TenantId" : "GUID" "ClientId" : "your application ID from the Entra ID app registration" } }
-
Add the nuget Microsoft.Identity.Web NuGet package
-
Add the following usings at the top of the file
using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.Identity.Web;
-
In the Program.cs file, after
var app = builder.Build();
, add:builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));
-
Replace
services.AddRazorPages()
by:services.AddRazorPages().AddMvcOptions(options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); }).AddMicrosoftIdentityUI(); }
-
After
app.UseAuthentication()
, use:app.UseAuthentication(); app.UseAuthorization(); // More code app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); // If Razor pages endpoints.MapControllers(); // Needs to be added }); }
-
In the controllers, add an
[Authorize]
attribute.
- 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