Auth Recipe — C# (.NET) — REFERENCE ONLY
Microsoft Identity Web (ASP.NET Core)
NuGet Packages
xml
Program.cs (additions)
Add these lines — do NOT replace the existing file:
csharp
using Microsoft.Identity.Web;
// Add after builder creation
builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration);
builder.Services.AddAuthorization();
// Add after app build
app.UseAuthentication();
app.UseAuthorization();
// Protected endpoint
app.MapGet("/api/me", [Authorize] (HttpContext ctx) =>
{
var name = ctx.User.FindFirst("name")?.Value;
return Results.Ok(new { name });
});appsettings.json
json
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",