Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/app-service/templates/recipes/auth/source/dotnet.md
1# Auth Recipe — C# (.NET) — REFERENCE ONLY23## Microsoft Identity Web (ASP.NET Core)45### NuGet Packages67```xml8<PackageReference Include="Microsoft.Identity.Web" Version="3.*" />9```1011### Program.cs (additions)1213Add these lines — do NOT replace the existing file:1415```csharp16using Microsoft.Identity.Web;1718// Add after builder creation19builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration);20builder.Services.AddAuthorization();2122// Add after app build23app.UseAuthentication();24app.UseAuthorization();2526// Protected endpoint27app.MapGet("/api/me", [Authorize] (HttpContext ctx) =>28{29var name = ctx.User.FindFirst("name")?.Value;30return Results.Ok(new { name });31});32```3334### appsettings.json3536```json37{38"AzureAd": {39"Instance": "https://login.microsoftonline.com/",40"TenantId": "<tenant-id>",41"ClientId": "<client-id>",42"Audience": "api://<client-id>"43}44}45```4647> ⚠️ The `Audience` must match the Application ID URI of the app registration (typically `api://<client-id>`). Set `AZURE_CLIENT_ID` and `AZURE_TENANT_ID` as app settings in Azure rather than hardcoding them.4849## Files to Modify5051| File | Action |52|------|--------|53| `Program.cs` | Add authentication middleware + protected endpoints |54| `appsettings.json` | Add AzureAd configuration section |55| `*.csproj` | Add Microsoft.Identity.Web NuGet package |56