Skip to content

Add .NET server_login_auth_code sample#29

Merged
ksroda-sa merged 5 commits into
mainfrom
feature/dotnet-login-auth-code-sample
Apr 23, 2026
Merged

Add .NET server_login_auth_code sample#29
ksroda-sa merged 5 commits into
mainfrom
feature/dotnet-login-auth-code-sample

Conversation

@ksroda-sa

Copy link
Copy Markdown
Collaborator

Summary

Introduces .NET as the fifth framework in the Quickstart samples repo and lands the first server_web / server_login_auth_code scenario.

  • samples/dotnet/login-auth-code/ — ASP.NET Core Minimal-APIs app on https://localhost:4260 using the built-in Microsoft.AspNetCore.Authentication.OpenIdConnect middleware
  • Framework scaffolding: placeholder-map.yaml (csharp section), .cs glob in extract/validate scripts, .csproj version fallback, new test-dotnet.yml CI workflow, root .gitignore additions

Approach

  • .NET 10 + Minimal APIs — single-file Program.cs mirrors the Node/Express teaching style
  • Built-in OIDC middleware — declarative AddAuthentication().AddCookie().AddOpenIdConnect(...); the middleware owns /callback, PKCE, state validation, and token storage
  • DotNetEnv for .env config — same user flow as Node samples and acp Quickstart
  • xUnit + WebApplicationFactory<Program> with a pre-populated OpenIdConnectConfiguration (bypasses discovery) and a fake auth scheme (TestAuthHandler) for the authenticated-user test

🤖 Generated with Claude Code

ksroda-sa and others added 4 commits April 22, 2026 13:23
- Minimal ASP.NET Core Minimal-APIs app targeting net10.0 using
  Microsoft.AspNetCore.Authentication.OpenIdConnect
- Port 4260 (HTTPS via dotnet dev-certs); cookie + OIDC auth schemes;
  SaveTokens + GetClaimsFromUserInfoEndpoint
- Env via DotNetEnv for parity with Node samples / acp Quickstart UX
- 4 xUnit + WebApplicationFactory tests covering / unauth, / auth,
  /login challenge, /logout sign-out (OIDC Configuration pre-populated
  to avoid discovery calls in tests)
- Regenerated snippets.json + snippet-manifest.yaml with new dotnet
  entry (3 snippet steps, install = manifest.lib, lib_version from
  .csproj regex)
- Bump CI workflow dotnet-version to 10.0.x to match the sample's
  target framework
- Default OIDC SignedOutCallbackPath (/signout-callback-oidc) — overriding
  to "/" makes the middleware swallow all requests to /

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…bber existing env

dotnet run --project src sets CWD to src/, so Env.Load() (which reads
./.env by default) couldn't find the .env at the sample root.

Switch to Env.TraversePath().NoClobber().Load() — traverses up from
CWD to find .env, and respects env vars already set in the process.
The NoClobber bit matters for tests: the fixture sets
ISSUER_URL/CLIENT_ID/etc. via Environment.SetEnvironmentVariable before
the app boots; without NoClobber a developer-local .env at the sample
root would clobber those values and the tests would fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…_name etc. work

Microsoft's OIDC middleware remaps inbound claims to long xmlsoap URIs
by default (given_name -> http://schemas.xmlsoap.org/.../givenname),
so user.FindFirst("given_name") in Program.cs returned null and the
page rendered "Welcome, there" against real tenants.

Setting MapInboundClaims = false keeps OIDC claim names as-is, so
FindFirst("given_name"/"family_name"/"email") lines up with both the
ID token payload and the claims our test fixture injects. Tests still
pass (4/4) because they already use the short claim names.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ksroda-sa ksroda-sa requested a review from Copilot April 23, 2026 07:46
@ksroda-sa ksroda-sa marked this pull request as ready for review April 23, 2026 07:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new .NET framework track to the quickstart samples, including a first server_web/server_login_auth_code scenario implemented as an ASP.NET Core Minimal API app, and updates the snippet tooling/CI to support C# projects.

Changes:

  • Introduces samples/dotnet/login-auth-code (Minimal API + cookie auth + OpenID Connect middleware) with xUnit integration tests.
  • Extends snippet extraction/validation to include .cs sources and infer library versions from .csproj when package.json is absent.
  • Adds .NET metadata to manifests/snippets plus a new GitHub Actions workflow to build/test .NET samples.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
snippets.json Adds extracted snippet steps + metadata for the new dotnet server_login_auth_code sample.
snippet-manifest.yaml Registers .NET framework and includes dotnet under server_login_auth_code scenario.
scripts/validate-structure.ts Allows .cs sources when validating sample structure/snippet tags.
scripts/extract-snippets.ts Adds .cs globbing, .csproj lib version fallback, and install fallback for non-Node projects.
samples/dotnet/manifest.yaml New framework manifest describing dotnet scenario metadata and config rows.
samples/dotnet/login-auth-code/tests/login-auth-code.tests.csproj New xUnit test project for the dotnet sample.
samples/dotnet/login-auth-code/tests/TestAuthHandler.cs Test auth handler used to simulate authenticated requests.
samples/dotnet/login-auth-code/tests/AuthIntegrationTests.cs Integration tests covering /, /login, and /logout flows.
samples/dotnet/login-auth-code/src/login-auth-code.csproj New ASP.NET Core app project targeting net10.0 with OIDC + DotNetEnv deps.
samples/dotnet/login-auth-code/src/Program.cs Minimal API implementation using cookie + OIDC middleware, plus simple HTML views.
samples/dotnet/login-auth-code/login-auth-code.sln Solution file grouping app + tests.
samples/dotnet/login-auth-code/README.md Setup/docs for running and testing the dotnet sample.
samples/dotnet/login-auth-code/.env.example Example env config for SecureAuth OIDC settings.
placeholder-map.yaml Adds C# placeholder mappings for env var access patterns.
.gitignore Ignores common .NET build artifacts (bin/, obj/, *.user).
.github/workflows/test-dotnet.yml New CI workflow to restore/build/test all .sln projects under samples/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread samples/dotnet/login-auth-code/tests/AuthIntegrationTests.cs Outdated
Comment thread samples/dotnet/login-auth-code/.env.example
Comment thread samples/dotnet/login-auth-code/src/Program.cs Outdated
Comment thread samples/dotnet/login-auth-code/src/Program.cs Outdated
Comment thread samples/dotnet/manifest.yaml Outdated
Comment thread samples/dotnet/login-auth-code/README.md Outdated
Comment thread samples/dotnet/login-auth-code/README.md Outdated
@ksroda-sa ksroda-sa merged commit d378929 into main Apr 23, 2026
25 checks passed
@ksroda-sa ksroda-sa deleted the feature/dotnet-login-auth-code-sample branch April 23, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants