duendesoftware/duende-skills/identityserver-ui-flows

Claude Code and agent skill by duendesoftware/duende-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Guide for building login, logout, consent, error, and federation gateway UI pages in Duende IdentityServer, including IIdentityServerInteractionService usage, external provider integration, and Home Realm Discovery strategies.

Install

npx vskill@latest install duendesoftware/duende-skills/identityserver-ui-flows

SKILL.md

The same SKILL.md was published earlier as duendesoftware/duende-skills/identityserver-ui-flows.

IdentityServer UI Flows: Login, Logout, Consent, and Federation

When to Use This Skill

  • Building or customizing the login page (local credentials, MFA, passwordless)
  • Integrating external identity providers (Google, Azure AD, SAML, etc.)
  • Implementing the consent page for third-party client authorization
  • Building the logout flow with session cleanup and client notifications
  • Implementing a federation gateway with Home Realm Discovery (HRD)
  • Handling and displaying error pages for protocol errors
  • Using IIdentityServerInteractionService to interact with the protocol engine
  • Redirecting users back to clients after login/logout

Docs: https://docs.duendesoftware.com/identityserver/ui

Architecture Overview

IdentityServer separates the protocol engine from the user interface. The engine handles OAuth/OIDC endpoints and redirects to your UI pages as needed. Your UI code handles all user interaction and then communicates results back to the engine.

Browser → IdentityServer Middleware → UI Pages (Login, Consent, Logout, Error)
↕
IIdentityServerInteractionService
↕
IdentityServer Protocol Engine
Required Pages
PagePurposeDefault URL
LoginEstablish authentication sessionInferred from cookie handler LoginPath
LogoutTerminate session, notify clientsSet via opt.UserInteraction.LogoutUrl
ConsentGrant/deny client access to resources/consent
ErrorDisplay protocol error information/home/error

Login Page

Configuring the Login URL
csharp
// Program.cs — explicit configuration
builder.Services.AddIdentityServer(opt => {
opt.UserInteraction.LoginUrl = "/path/to/login";
});

If not set, IdentityServer infers the URL from the cookie handler's LoginPath:

csharp
// Program.cs — with ASP.NET Identity
builder.Services.AddIdentityServer()
.AddAspNetIdentity<ApplicationUser>();
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/path/to/login/for/aspnet_identity";
});
Authorization Context

When IdentityServer redirects to the login page, it passes a returnUrl query parameter. Use IIdentityServerInteractionService.GetAuthorizationContextAsync to extract the original authorization request parameters:

csharp
public class LoginModel : PageModel
{
private readonly IIdentityServerInteractionService _interaction;
public LoginModel(IIdentityServerInteractionService interaction)
{
_interaction = interaction;
}
public async Task<IActionResult> OnGet(string returnUrl)
{
var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
// context contains:
// - Client (the requesting client)
// - IdP (requested identity provider hint)
// - AcrValues (requested authentication context)
// - Tenant (requested tenant)
// - LoginHint (suggested username)
// - Parameters (raw protocol parameters)
// Use context for branding, HRD, MFA decisions, etc.
}
}

Important: Do not parse the returnUrl yourself. Always use the interaction service.

Establishing the Authentication Session

After validating credentials, create the authentication session:

csharp
var user = new IdentityServerUser("unique_id_for_your_user")
{
DisplayName = "Bob Smith"
};
await HttpContext.SignInAsync(user);
// Redirect back to the authorization endpoint
return Redirect(returnUrl);

Or with explicit claims:

csharp
var claims = new Claim[] {
new Claim("sub", "unique_id_for_your_user"),
new Claim("name", "Bob Smith"),
new Claim("amr", "pwd"),
new Claim("idp", "local")
};
var identity = new ClaimsIdentity(claims, "pwd");
var principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(principal);
Well-Known Session Claims
ClaimPurposeDefault
subRequired. Unique user identifier. Must never change or be reassigned.None — you must provide it
nameDisplay name of the userNone
amrAuthentication method referencepwd
auth_timeTime user entered credentials (epoch)Current time
idpIdentity provider scheme namelocal
tenantTenant identifierNone
Protecting Against Open Redirects

Always validate the returnUrl before redirecting:

csharp
// Option 1: Use ASP.NET Core helper
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
// Option 2: Use IdentityServer interaction service
if (await _interaction.IsValidReturnUrl(returnUrl))
{
return Redirect(returnUrl);
}
Completing Login with CompleteLoginAsync

After establishing the authentication session, redirect the user back to the returnUrl. This causes the browser to re-issue the original authorize request, allowing IdentityServer to complete the protocol workflow.

External Login (Federation)

Registering External Providers
csharp
// Program.cs
builder.Services.AddIdentityServer();
builder.Services.AddAuthentication()
.AddOpenIdConnect("AAD", "Employee Login", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
// configure authority, client ID, etc.
});
Triggering External Authentication
csharp
var callbackUrl = Url.Action("MyCallback");
var props = new AuthenticationProperties
{
RedirectUri = callbackUrl,
Items =
{
{ "scheme", "AAD" },
{ "returnUrl", returnUrl }
}
};
return Challenge("AAD", props);
Handling the Callback
csharp
// 1. Read external identity from temporary cookie
var result = await HttpContext.AuthenticateAsync(
IdentityServerConstants.ExternalCookieAuthenticationScheme);
if (result?.Succeeded != true)
throw new Exception("External authentication error");
var externalUser = result.Principal;
var userId = externalUser.FindFirst("sub").Value;
var scheme = result.Properties.Items["scheme"];
var returnUrl = result.Properties.Items["returnUrl"] ?? "~/";
// 2. Find or provision local user
var user = FindUserFromExternalProvider(scheme, userId);
// 3. Establish session
await HttpContext.SignInAsync(new IdentityServerUser(user.SubjectId)
{
DisplayName = user.DisplayName,
IdentityProvider = scheme
});
// 4. Clean up external cookie
await HttpContext.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);
// 5. Return to protocol processing
return Redirect(returnUrl);
SignInScheme and SignOutScheme
ScenarioSignInSchemeSignOutScheme
Without ASP.NET IdentityIdentityServerConstants.ExternalCookieAuthenticationSchemeIdentityServerConstants.SignoutScheme
With ASP.NET IdentityIdentityServerConstants.ExternalCookieAuthenticationSchemeIdentityConstants.ApplicationScheme
State and URL Length

If external provider state makes the URL too long (>2000 chars), use the IdentityServer-provided IDistributedCache-backed data format:

csharp
// Program.cs — all OIDC handlers use server-side state
builder.Services.AddOidcStateDataFormatterCache();
// Or specific schemes only
builder.Services.AddOidcStateDataFormatterCache("aad", "demoidsrv");

Logout Page

Configuring the Logout URL
csharp
// Program.cs
builder.Services.AddIdentityServer(opt => {
opt.UserInteraction.LogoutUrl = "/path/to/logout";
});
Logout Steps
  1. End the IdentityServer session — remove the authentication cookie
  2. Sign out of external provider — if an external login was used
  3. Notify client applications — via front-channel, back-channel, or JS-based notifications
  4. Redirect back to client — if the logout is client-initiated
Client Notification Mechanisms
MechanismHow It WorksClient Setting
Front-channelRender <iframe> on logged-out page pointing to client's logout URIFrontChannelLogoutUri
Back-channelServer-to-server HTTP call with a logout JWT (typ: logout+jwt)BackChannelLogoutUri
JS-basedClient monitors check_session_iframeBuilt into spec-compliant JS clients

Recommendation: Use back-channel notifications for cross-site architectures. Front-channel and JS-based notifications rely on cookies in iframes, which may not work reliably across different sites.

Getting Logout Context
csharp
var context = await _interaction.GetLogoutContextAsync(logoutId);
// context.SignOutIFrameUrl — render in <iframe> for front-channel logout
// context.PostLogoutRedirectUri — where to send the user after logout
Back-Channel Logout

Back-channel logout happens automatically when you call HttpContext.SignOutAsync() — IdentityServer uses IBackChannelLogoutService to notify all clients that have BackChannelLogoutUri configured.

For .NET clients: use the BFF framework which has built-in back-channel logout support, or see the IdentityServer samples.

Consent Page

When Consent Is Required

Consent applies only to user-based (interactive) authorization requests. Client-credentials (M2M) flows never prompt for consent — there Client.AllowedScopes alone governs access.

Consent is controlled per client via RequireConsent (default: false). Set RequireConsent = false for first-party clients to suppress the scope prompt; set true for third-party clients. When enabled, IdentityServer redirects to the consent page before completing authorization.

The offline_access scope always triggers consent when the client has consent enabled.

Required vs. Optional Scopes

IdentityResource and ApiScope expose a Required bool:

  • If the consent response omits a `Required` scope, IdentityServer returns access_denied and the request fails.
  • Optional scopes can be declined and the flow still succeeds — the issued tokens/userinfo simply omit that data.
csharp
new IdentityResource("profile", /* ... */) { Required = true }; // cannot be declined
new ApiScope("api.read") { Required = false }; // may be declined
Remembered Consent

Enable persistence with Client.AllowRememberConsent (bool) and Client.ConsentLifetime (expiry). Granted scopes are stored in the operational (persisted grant) store; set RememberConsent = true on the ConsentResponse to persist a grant.

IdentityServer re-prompts for consent when:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
9
Repository forks
3
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/duendesoftware/duende-skills/identityserver-ui-flows/badge)](https://verified-skill.com/skills/duendesoftware/duende-skills/identityserver-ui-flows)

Something wrong with this skill or its page? Tell us.