EasyAuthSimulator.Hosting
0.3.0
dotnet add package EasyAuthSimulator.Hosting --version 0.3.0
NuGet\Install-Package EasyAuthSimulator.Hosting -Version 0.3.0
<PackageReference Include="EasyAuthSimulator.Hosting" Version="0.3.0" />
<PackageVersion Include="EasyAuthSimulator.Hosting" Version="0.3.0" />
<PackageReference Include="EasyAuthSimulator.Hosting" />
paket add EasyAuthSimulator.Hosting --version 0.3.0
#r "nuget: EasyAuthSimulator.Hosting, 0.3.0"
#:package EasyAuthSimulator.Hosting@0.3.0
#addin nuget:?package=EasyAuthSimulator.Hosting&version=0.3.0
#tool nuget:?package=EasyAuthSimulator.Hosting&version=0.3.0
EasyAuth Simulator
A local stand-in for Azure Container Apps' built-in authentication ("EasyAuth"), for developing and debugging container apps locally with real, authenticated users.
It's a YARP reverse proxy that performs a genuine OIDC sign-in against Microsoft Entra ID or any other OpenID Connect–compliant provider, then injects the same X-MS-CLIENT-PRINCIPAL* / X-MS-TOKEN-* headers and exposes the same /.auth/* endpoints that Container Apps EasyAuth does in production, before forwarding the request to your app. Your app needs zero auth-related code changes between local development and Azure.
Contents
- Supported identity providers
- Project layout
- Running with Aspire
- Running standalone
- Developing EasyAuthSimulator
- Known deviations from the real service
- Tests
- Distributing the simulator
Supported identity providers
| Provider | Real EasyAuth | EasyAuthSimulator |
|---|---|---|
| Microsoft Entra ID | Yes — built-in (aad) |
Yes — WithEntraId() |
| Any OpenID Connect–compliant provider (Google, Apple, Auth0, Okta, Duende IdentityServer, ...) | Yes — "Custom OpenID Connect" | Yes — WithCustomOpenIdConnect() |
| Yes — built-in | No — Facebook Login isn't OpenID Connect–compliant, so there's no metadata document for WithCustomOpenIdConnect() to discover either |
|
| GitHub | Yes — built-in | No — same reason; GitHub's OAuth apps don't implement OpenID Connect |
| X (formerly Twitter) | Yes — built-in | No — same reason; OAuth, not OpenID Connect |
Client-directed sign-in (POST a provider token to /.auth/login/<provider> for validation, then use X-ZUMO-AUTH, instead of a browser redirect) |
Yes | No — not yet implemented, see Known deviations |
Facebook, GitHub, and X aren't reachable through WithCustomOpenIdConnect() either, since none of them expose a standards-compliant .well-known/openid-configuration document for it to discover — see Adding another identity provider if you need one of those.
Project layout
src/EasyAuthSimulator— the proxy, distributed as a container image (see theDockerfile).src/EasyAuthSimulator.Hosting— an Aspire hosting integration (AddEasyAuthSimulator()etc.) that runs that image as a container resource; a tiny library with no dependency on the proxy's own build output.samples/SampleApp— a minimal API that reads the injected headers.samples/SampleApp.AppHost— runs the sample via a C# AppHost.samples/SampleApp.AppHost.TypeScript— the same sample, wired up via a TypeScript AppHost instead.tests/EasyAuthSimulator.Tests— contract tests against the documented EasyAuth header/endpoint behavior.
Running with Aspire
Using the published packages
Both artifacts described in Distributing the simulator are published
publicly from this repo's CI: the easyauthsimulator container image to the GitHub Container
Registry, and the EasyAuthSimulator.Hosting NuGet package to GitHub Packages.
Container image — this is the default; AddEasyAuthSimulator pulls
ghcr.io/mfcollins3/easyauthsimulator anonymously and automatically, tagged to match whichever
version of EasyAuthSimulator.Hosting you have installed, so nothing below is required just to
use it:
builder.AddEasyAuthSimulator("auth")
.WithUpstream(api)
.WithEntraId(tenantId, clientId, secret)
.WithExternalHttpEndpoints();
You can still pull it yourself to inspect it or run it outside Aspire:
docker pull ghcr.io/mfcollins3/easyauthsimulator:<version>
NuGet package — also public, but GitHub Packages requires an authenticated pull for every
package it hosts, public or not (there's no anonymous-read exception the way there is for GHCR
container images). You'll need a classic personal access token with the read:packages scope
(fine-grained tokens aren't supported for package installs):
dotnet nuget add source https://nuget.pkg.github.com/mfcollins3/index.json \
--name easyauthsimulator-github \
--username <your-github-username> \
--password <your-personal-access-token> \
--store-password-in-clear-text
From a C# AppHost:
dotnet add package EasyAuthSimulator.Hosting --version <version> --source easyauthsimulator-github
From a TypeScript AppHost, once the source above is configured:
aspire add EasyAuthSimulator.Hosting --version <version> --source easyauthsimulator-github
Either way, swap in the latest version from the package's version history.
Common setup
var api = builder.AddProject<Projects.MyApi>("api");
builder.AddEasyAuthSimulator("auth")
.WithUpstream(api)
// .WithEntraId(...) and/or .WithCustomOpenIdConnect(...) go here — see below
.WithExternalHttpEndpoints();
AddEasyAuthSimulator needs your AppHost to reference EasyAuthSimulator.Hosting.csproj (IsAspireProjectResource="false", since the simulator runs as a container resource rather than an Aspire project resource) — see samples/SampleApp.AppHost/SampleApp.AppHost.csproj. By default it runs the published container image above; to run one you build locally instead (e.g. while working on the simulator itself), override it with .WithImage("easyauthsimulator").
WithUpstream accepts any Aspire resource with an HTTP endpoint, so api above can just as well be a Go executable (AddExecutable) or a Node app (Aspire's JavaScript hosting integration).
The port is pinned, not Aspire-allocated. An identity provider validates the redirect URI against how you registered your app with it, so a random port would break sign-in on every run. Pick a port, register that exact redirect URI with your provider, and pass the same port via EasyAuthSimulatorOptions.Port (it defaults to 8080, which is what the examples below rely on):
builder.AddEasyAuthSimulator("auth", new EasyAuthSimulatorOptions { Port = 8081 })
Then wire up one or more identity providers — see below.
Using the Entra ID provider
- Register an app in your tenant (Entra admin center → App registrations → New registration).
- Add a Redirect URI (platform: Web) of
http://localhost:8080/.auth/login/aad/callback— adjust the port if you configure a differentEASYAUTH_PORT/EasyAuthSimulatorOptions.Port. Entra only permits plainhttp://forlocalhost. - Create a client secret (Certificates & secrets).
- Enable ID token issuance, which Container Apps' own docs call out as required for EasyAuth:
az ad app update --id <app-id> --enable-id-token-issuance true
You'll need the tenant ID, client ID, and client secret from this registration:
var secret = builder.AddParameter("entra-client-secret", secret: true);
var tenantId = builder.AddParameter("entra-tenant-id");
var clientId = builder.AddParameter("entra-client-id");
builder.AddEasyAuthSimulator("auth")
.WithUpstream(api)
.WithEntraId(tenantId, clientId, secret)
.WithExternalHttpEndpoints();
Put the tenant ID, client ID, and secret in user secrets (Parameters:entra-tenant-id, etc.) — never in source.
See samples/SampleApp.AppHost/AppHost.cs for a complete example.
Using a custom OpenID Connect provider
WithCustomOpenIdConnect() wires up any spec-compliant OpenID Connect provider — Google, Apple, Auth0, Okta, Duende IdentityServer, your own IdentityServer/OpenIddict instance, etc. — discovered via its {authority}/.well-known/openid-configuration metadata document, no code required. Call it once per provider with a distinct name to enable more than one; each signs in at /.auth/login/<name>:
builder.AddEasyAuthSimulator("auth")
.WithUpstream(api)
.WithCustomOpenIdConnect(
"duende",
"https://demo.duendesoftware.com",
builder.AddParameter("duende-client-id"),
builder.AddParameter("duende-client-secret", secret: true))
.WithExternalHttpEndpoints();
You can combine this with .WithEntraId(...) to offer more than one provider. When you do, requests are unauthenticated by default (EasyAuthSimulatorOptions.AuthenticationRequired = false), so your app can render its own sign-in picker instead of being redirected straight into a single provider; set AuthenticationRequired = true (and DefaultProvider, if more than one provider is configured) to require sign-in instead. See samples/SampleApp.AppHost/AppHost.cs and samples/SampleApp/Program.cs for a complete example with two providers and a picker page.
From a TypeScript AppHost
The same methods (AddEasyAuthSimulator, WithUpstream, WithEntraId, WithCustomOpenIdConnect) are
available from a TypeScript AppHost — no C# authoring required on your side, just a reference to this
project so the CLI can generate typed bindings for it:
const tenantId = builder.addParameter('entra-tenant-id');
const clientId = builder.addParameter('entra-client-id');
const clientSecret = builder.addParameter('entra-client-secret', { secret: true });
const api = await builder.addProject('api', '../MyApi');
await builder
.addEasyAuthSimulator('auth')
.withUpstream(api)
.withEntraId(tenantId, clientId, clientSecret)
.withExternalHttpEndpoints();
Add it to your AppHost's aspire.config.json under packages, pointing at the hosting project by
path for local development (see Using the published packages above
for the published-NuGet-package form instead):
{
"packages": {
"EasyAuthSimulator": "../../path/to/EasyAuthSimulator.Hosting.csproj"
}
}
Then run aspire restore to regenerate the SDK, or just aspire run. See
samples/SampleApp.AppHost.TypeScript/apphost.mts for the complete, working example.
Running standalone
export EASYAUTH_PORT=8080
export EASYAUTH_UPSTREAM_URL=http://localhost:5000
export EASYAUTH_AAD_TENANT_ID=<tenant-id>
export EASYAUTH_AAD_CLIENT_ID=<client-id>
export EASYAUTH_AAD_CLIENT_SECRET=<client-secret>
dotnet run --project src/EasyAuthSimulator
Configuration (environment variables)
| Variable | Default | Purpose |
|---|---|---|
EASYAUTH_PORT |
8080 | Listen port. |
EASYAUTH_UPSTREAM_URL |
(required) | The app to forward authenticated requests to. |
EASYAUTH_PROVIDER |
aad |
Default provider used when redirecting to sign in. |
EASYAUTH_AAD_TENANT_ID / _CLIENT_ID / _CLIENT_SECRET |
(required) | Your Entra app registration. |
EASYAUTH_AAD_AUTHORITY_HOST |
login.microsoftonline.com |
Override for sovereign clouds. |
EASYAUTH_AAD_SCOPES |
openid;profile;email;offline_access |
;-separated. offline_access is required for a refresh token. |
EASYAUTH_OIDC_<NAME>_CLIENT_ID / _CLIENT_SECRET |
(required per provider) | Registers a custom OpenID Connect provider named <NAME> (e.g. EASYAUTH_OIDC_DUENDE_CLIENT_ID). <NAME> must be alphanumeric and can't be AAD. |
EASYAUTH_OIDC_<NAME>_AUTHORITY |
(required, unless _METADATA_ADDRESS is set) |
The provider's issuer; metadata is discovered at {authority}/.well-known/openid-configuration. |
EASYAUTH_OIDC_<NAME>_METADATA_ADDRESS |
— | An explicit metadata document URL, for a provider that doesn't follow the issuer + /.well-known/openid-configuration convention. |
EASYAUTH_OIDC_<NAME>_SCOPES |
openid;profile;email |
;-separated. |
EASYAUTH_OIDC_<NAME>_NAME_CLAIM_TYPE / _ROLE_CLAIM_TYPE |
name / roles |
Overrides which claim in the provider's tokens backs the principal name/roles. |
EASYAUTH_REQUIRE_AUTHENTICATION |
true |
Mirrors globalValidation.requireAuthentication. |
EASYAUTH_UNAUTHENTICATED_ACTION |
RedirectToLoginPage |
RedirectToLoginPage | AllowAnonymous | Return401 | Return403 | Return404 (or the RejectWith401/RejectWith404 file-config spellings). |
EASYAUTH_EXCLUDED_PATHS |
— | ;-separated; entries may end in /* for a prefix match. |
EASYAUTH_API_PREFIX |
/.auth |
Relocates the /.auth/* surface. |
EASYAUTH_FORWARD_PROXY_CONVENTION |
Standard |
NoProxy | Standard | Custom. |
EASYAUTH_CUSTOM_PROTO_HEADER_NAME / _HOST_HEADER_NAME |
— | Used when the convention above is Custom. |
EASYAUTH_FORWARD_ORIGINAL_HOST |
true |
Forwards the original ingress Host header to your app. |
EASYAUTH_ALLOWED_EXTERNAL_REDIRECT_HOSTS |
— | ;-separated hosts allowed for post_login_redirect_uri/post_logout_redirect_uri beyond the current host. |
Developing EasyAuthSimulator
This section is for working on EasyAuthSimulator itself. If you just want to use it, see Running with Aspire instead.
Building the container image locally
AddEasyAuthSimulator pulls the published image by default (see Using the published packages), so to pick up local changes to the proxy, build it and point at it explicitly:
docker build -t easyauthsimulator:latest -f src/EasyAuthSimulator/Dockerfile .
Run this from the repo root — the Dockerfile's COPY . . and publish path assume a repo-root
build context, not the src/EasyAuthSimulator directory. Then override the default with .WithImage("easyauthsimulator") on the resource AddEasyAuthSimulator returns (or .WithImageRegistry() / .WithImageTag() to point at a different published image). If you're publishing a build for others to consume, see Distributing the simulator below instead.
Adding another identity provider
If the provider speaks standard OpenID Connect, you don't need to add anything — use WithCustomOpenIdConnect() (see Using a custom OpenID Connect provider) instead. This section is for a provider that isn't OIDC-compliant (e.g. Facebook, GitHub, X — see Supported identity providers).
Implement IEasyAuthProvider (src/EasyAuthSimulator/Providers/IEasyAuthProvider.cs) and register it alongside its authentication handler in a AddXxx() extension method modeled on EntraIdServiceCollectionExtensions.AddEntraId(). Nothing else in the pipeline needs to change — routing, header injection, and the /.auth/* endpoints are all provider-agnostic.
Known deviations from the real service
A few details of real EasyAuth are undocumented publicly and are called out with [inferred] comments in the source where a best-effort guess was made instead of a confirmed behavior — notably which claim backs X-MS-CLIENT-PRINCIPAL-ID for Entra ID, the exact /.auth/me schema, and the session cookie's name/chunking behavior. Not yet implemented: the X-ZUMO-AUTH client-directed POST login flow, and the Origin/Referer CSRF check real EasyAuth applies to cookie-authenticated POSTs.
Tests
dotnet test
Distributing the simulator
Two artifacts ship together, from the same release tag (.github/workflows/release.yml), always
at the same version number:
- The
easyauthsimulatorcontainer image — the actual proxy, published toghcr.io/mfcollins3/easyauthsimulatortagged with the release version (pluslatestand rollingmajor/major.minortags). Build and push your own with:
Run this from the repo root, for the same reason noted above.docker build -t <your-registry>/easyauthsimulator:<version> -f src/EasyAuthSimulator/Dockerfile . docker push <your-registry>/easyauthsimulator:<version> - The
EasyAuthSimulator.HostingNuGet package — the Aspire hosting integration. Its default image tag (seeEasyAuthSimulatorResourceBuilderExtensions) is resolved from its own assembly version at runtime, so installingEasyAuthSimulator.HostingversionX.Y.Zpullsghcr.io/mfcollins3/easyauthsimulator:X.Y.Zwithout any extra configuration. Pack it yourself with:
Push the resultingdotnet pack src/EasyAuthSimulator.Hosting/EasyAuthSimulator.Hosting.csproj -c Release -o ./nupkg.nupkgto whatever feed you use (a local folder feed, Azure Artifacts, GitHub Packages, etc.) — seedotnet nuget push.
See Using the published packages above for how consumers pull
these once published — this repo's own CI publishes both artifacts on every tagged release (see
.github/workflows/release.yml).
If you fork this repo or publish your own build under a different name/tag, override the default
per-AppHost with .WithImageRegistry() / .WithImage() / .WithImageTag() on the resource
AddEasyAuthSimulator returns, rather than forking the hosting package.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Aspire.Hosting (>= 13.5.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.0 | 130 | 9/27/2026 |