Test Blazor sign-in without an Entra ID tenant

Test sign-in, sign-out and role-based navigation in a server-rendered Blazor Web App with Microsoft.Identity.Web.

Verified with .NET 10.0, .NET SDK 10.0.404, Microsoft.Identity.Web 4.18.0.

The problem

A Blazor app that uses Microsoft.Identity.Web normally needs an Entra app registration and users assigned to roles. That makes it harder to reproduce a reader being denied or to give every CI run the same test users.

Why HeyIdentity fits

The Microsoft profile serves Entra ID v2.0 discovery and tokens with your configured roles. The example uses a public client with S256 PKCE. The server reads the ID-token hint from the protected session cookie when signing out.

Prerequisites

Install .NET SDK 10.0.404, Node.js 22.12 or later, and Git. The SDK can be installed alongside other versions. If the checkout reports that a compatible .NET SDK was not found, install 10.0.404 and check dotnet --version at the checkout root.

Clone the verified example

Start in the directory where you keep your repositories. These commands open the revision used for this guide. Browse the runnable example on GitHub.

git clone https://github.com/heyidentity/examples.git heyidentity-examples
cd heyidentity-examples
git checkout --detach 391c07e010699fff660fa3b4c9f4ce86cd6fa234

Set up HeyIdentity

Reuse an active configuration if it uses the Microsoft profile and the issuer, client and registered URLs match this example. Register http://localhost:5173/signin-oidc for sign-in and http://localhost:5173/ for sign-out. Stop the previous app before running this one, or use an unused APP_PORT and register the corresponding URLs.

For a different profile, incompatible settings or an expired configuration, start from a separate checkout so the old .env and agent token remain available. Temporary setup asks you to accept the Terms of Use. An unclaimed configuration expires after seven days. Claim or recover a setup.

Use a temporary configuration

From the checkout root, provision a Microsoft-profile configuration and write the root settings file.

node setup/provision.mjs --temporary --profile microsoft

Use a configuration you own

Copy .env.example to .env. In Connect your app → All endpoints and IDs, copy Instance to ENTRA_INSTANCE and Configuration id (Entra tenant ID) to ENTRA_TENANT_ID. Set OIDC_AUTHORITY to the Entra issuer https://app.heyidentity.dev/{configurationId}/v2.0.

Copy the client ID from Clients to OIDC_CLIENT_ID and add the exact URLs above. The example signs in as a public client with S256 PKCE and reads no client secret, so keep secret validation off for this client. Set ADMIN_USER_KEY and READER_USER_KEY to the keys of two test users with roles of ["admin"] and ["reader"] respectively.

How the app configures Microsoft.Identity.Web

builder.Configuration["AzureAd:Instance"] = instanceUri.AbsoluteUri;
builder.Configuration["AzureAd:TenantId"] = tenantId;
builder.Configuration["AzureAd:ClientId"] = settings.Require("OIDC_CLIENT_ID");
builder.Configuration["AzureAd:CallbackPath"] = "/signin-oidc";
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));

Run and verify

Restore and start Blazor from the checkout root.

dotnet restore apps/blazor/Blazor.csproj --locked-mode
dotnet run --project apps/blazor/Blazor.csproj --no-restore --no-launch-profile

Open http://localhost:5173/ and sign in as the admin. Open /admin and verify that the admin area appears. Sign out and repeat with the reader. The page should show the reader’s identity and Access denied. A successful sign-out returns to the exact app root and offers sign-in again.

For automated verification, stop the manually started app and add these settings to the root .env. They start this app and check its callback path.

EXAMPLE_APP_COMMAND="dotnet run --project apps/blazor/Blazor.csproj --no-build --no-launch-profile"
EXAMPLE_OIDC_CALLBACK_PATH=/signin-oidc

Run the test commands from the checkout root.

dotnet build apps/blazor/Blazor.csproj --no-restore
cd playwright/typescript
npm ci
npx playwright install chromium
npx playwright test

Limitations

This example covers a server-rendered Blazor Web App. Blazor WebAssembly uses browser-side MSAL.js and is outside this setup. For downstream API token acquisition in a server app, see the Microsoft.Identity.Web and MSAL guide. HeyIdentity is for development and testing.

Set up your own test configuration

Sign up