skip to content

Sign-In & Permissions

How an ASP.NET Core app learns who the caller is and what they may do: authentication schemes and handlers, ASP.NET Core Identity and authorization policies. Every interview level probes it.

part ofASP.NET Coreread it →
on this pageshow

explore

questions

29

In ASP.NET Core, what do [Authorize] and [AllowAnonymous] do on controllers and actions, and how do Minimal API endpoints express the same rules?

level: juniorimportance: must knowfreq 80%

basics

~20 s

[Authorize] marks an endpoint as needing authorization: bare, it applies DefaultPolicy (an authenticated user); Policy, Roles or AuthenticationSchemes narrow it. [AllowAnonymous] switches enforcement off. Minimal APIs chain RequireAuthorization() and AllowAnonymous(), or put the same attributes on the handler.

open as a page

In ASP.NET Core Identity, what do UserManager<TUser> and SignInManager<TUser> each do when a user registers and then signs in?

level: juniorimportance: must knowfreq 68%

basics

~20 s

UserManager manages stored users through a store: creating them, hashing and checking passwords, confirming e-mail, roles and lockout counts. SignInManager turns a verified user into a signed-in session by running the sign-in checks and issuing the Identity.Application cookie.

open as a page

In ASP.NET Core, how do you make a Web API accept an identity provider's access tokens with AddJwtBearer, and what does the handler do?

level: juniorimportance: must knowfreq 78%

basics

~10 s

Reference Microsoft.AspNetCore.Authentication.JwtBearer, call AddAuthentication().AddJwtBearer() with Authority and Audience, and mark endpoints with [Authorize] or RequireAuthorization. The handler reads the Bearer header, validates the token and puts its claims in HttpContext.User.

open as a page

In ASP.NET Core, what do the default scheme settings on AddAuthentication control, and what happens when no default challenge scheme can be resolved?

level: middleimportance: must knowfreq 60%

basics

~20 s

AuthenticationOptions holds a default scheme for each action (authenticate, challenge, forbid, sign-in, sign-out) with DefaultScheme as the fallback. If none resolves and nothing names a scheme, the call throws an InvalidOperationException saying no default scheme was found.

open as a page

In ASP.NET Core, how do you build a policy from a custom requirement and an AuthorizationHandler<T>, and how are several handlers' results combined?

level: middleimportance: must knowfreq 62%

basics

~10 s

A policy lists requirements (IAuthorizationRequirement); handlers deriving from AuthorizationHandler<TRequirement> call context.Succeed(requirement) when it is met. Every requirement must succeed, any one handler can satisfy a requirement, and a single context.Fail() fails the whole evaluation.

open as a page

In ASP.NET Core Identity, how do AddIdentity, AddDefaultIdentity and AddIdentityCore differ in what they register, and what do you chain after each?

level: middleimportance: must knowfreq 52%

basics

~20 s

AddIdentity registers user and role managers, SignInManager and the Identity cookie schemes. AddDefaultIdentity adds the Razor Pages UI and token providers but no roles. AddIdentityCore registers only UserManager; you chain AddSignInManager, AddRoles and AddDefaultTokenProviders yourself.

open as a page

In ASP.NET Core's AddJwtBearer, when do you configure Authority and Audience, and when TokenValidationParameters.IssuerSigningKey instead — and what must each setup supply?

level: middleimportance: must knowfreq 62%

basics

~20 s

Use Authority and Audience when an OpenID Connect provider publishes metadata: the handler discovers the issuer and signing keys. Use IssuerSigningKey only when you hold the key yourself; then you must also set ValidIssuer and ValidAudience, because nothing discovers them.

open as a page

In ASP.NET Core, how does AddGoogle let users sign in with a Google account, and what does its handler do when Google redirects back?

level: juniorimportance: should knowfreq 35%

basics

~20 s

AddGoogle registers an OAuth-based remote handler: a challenge redirects to Google, and on /signin-google it exchanges the code, reads Google's userinfo endpoint, maps the JSON to claims and signs the principal into a cookie scheme.

open as a page

When an ASP.NET Core authorization policy fails, how does the framework choose between a 401 challenge and a 403 forbid, and what shapes each response?

level: middleimportance: should knowfreq 52%

basics

~20 s

The authorization middleware forbids when the user authenticated but failed the policy, and challenges when nobody authenticated. The authentication scheme then writes the response: JwtBearer sends 401 or 403, while the cookie handler redirects browsers to LoginPath or AccessDeniedPath.

open as a page

In ASP.NET Core Identity, what do the default Password and Lockout options enforce, and why can lockout still never trigger on a login page?

level: middleimportance: should knowfreq 50%

basics

~20 s

Defaults: passwords of at least 6 characters with a digit, lowercase, uppercase and non-alphanumeric character; lockout after 5 failures for 5 minutes. Failures count only when PasswordSignInAsync gets lockoutOnFailure: true, which the default login pages do not pass.

open as a page

In ASP.NET Core JWT bearer authentication, why is a token whose exp has just passed still accepted, and which TokenValidationParameters settings govern token lifetime checks?

level: middleimportance: should knowfreq 48%

basics

~10 s

TokenValidationParameters.ClockSkew defaults to five minutes, so an expired token stays valid until exp plus five minutes. ValidateLifetime enables the exp and nbf checks, and RequireExpirationTime rejects tokens with no exp.

open as a page

With ASP.NET Core's AddOpenIdConnect, why can a claim the identity provider issues be missing from HttpContext.User, and which options bring it back?

level: middleimportance: should knowfreq 42%

basics

~20 s

The OpenID Connect handler builds User from the validated ID token, deletes protocol claims via ClaimActions and reads userinfo only when GetClaimsFromUserInfoEndpoint is true. Even then a userinfo field becomes a claim only if a ClaimAction maps its JSON key.

open as a page

With ASP.NET Core's AddOpenIdConnect, why is a signed-out user often signed straight back in, and how do you sign out properly?

level: middleimportance: should knowfreq 38%

basics

~20 s

Signing out of the cookie scheme ends only the app's session; the identity provider's session survives, so the next challenge signs the user back in silently. Sign out of both the cookie and the OpenIdConnect schemes, which redirects to the provider's end-session endpoint.

open as a page

In ASP.NET Core 10, why does an unauthenticated call to a cookie-protected [ApiController] action get 401 instead of a redirect to LoginPath, and how do you control it?

level: seniorimportance: should knowfreq 42%

basics

~10 s

Since ASP.NET Core 10, the cookie handler's default OnRedirectToLogin and OnRedirectToAccessDenied answer 401 or 403 instead of redirecting when the endpoint carries IDisableCookieRedirectMetadata, which [ApiController], JSON Minimal APIs, TypedResults and SignalR add automatically.

open as a page

In ASP.NET Core, when does IClaimsTransformation.TransformAsync run, and what goes wrong when it is used to add claims from a database?

level: seniorimportance: should knowfreq 40%

basics

~20 s

IClaimsTransformation.TransformAsync runs after every successful AuthenticateAsync, on every authenticated request and possibly several times per request. Its claims are never saved to the cookie, so it must be idempotent and cheap, or each request pays a database lookup.

open as a page

In ASP.NET Core, how would you let one app accept cookie sign-in for a parents' portal and an API key for a partner feed, using a custom handler and AddPolicyScheme?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Write an AuthenticationHandler that turns a valid key into an AuthenticateResult.Success ticket, register it with AddScheme next to AddCookie, and make an AddPolicyScheme the default whose ForwardDefaultSelector sends partner requests to the key scheme and everything else to cookies.

open as a page

In ASP.NET Core, how do AuthorizationOptions.DefaultPolicy and FallbackPolicy differ, and what changes when the fallback requires an authenticated user?

level: seniorimportance: should knowfreq 42%

basics

~20 s

DefaultPolicy applies where authorization is declared without a policy name, such as a bare [Authorize]; it requires an authenticated user. FallbackPolicy, null by default, applies where no authorization metadata exists. Setting it makes every undecorated endpoint require sign-in, so public ones need [AllowAnonymous].

open as a page

In an ASP.NET Core contract-management API, how do you let only a document's owner or a manager edit it, when [Authorize] runs before the document is loaded?

level: seniorimportance: should knowfreq 55%

basics

~10 s

Load the document first, then call IAuthorizationService.AuthorizeAsync(User, document, policyOrRequirement). Handlers deriving from AuthorizationHandler<TRequirement, Document> receive the document: one succeeds for its owner, another for managers. On failure, return Forbid() for a signed-in user.

open as a page

In ASP.NET Core, what do AddIdentityApiEndpoints and MapIdentityApi provide, and how do the bearer tokens /login returns differ from JWTs issued by an identity provider?

level: seniorimportance: should knowfreq 40%

basics

~20 s

AddIdentityApiEndpoints registers Identity with a bearer-token scheme and cookies; MapIdentityApi maps JSON endpoints such as /register, /login and /refresh. Its tokens are Data Protection–protected tickets readable only by the same app, not JWTs other APIs can validate.

open as a page

In ASP.NET Core Identity, how do e-mail confirmation and password-reset tokens work, and why does changing a user's security stamp invalidate those tokens and signed-in cookies?

level: seniorimportance: should knowfreq 38%

basics

~20 s

AddDefaultTokenProviders registers DataProtectorTokenProvider as the Default provider: tokens embed time, user id, purpose and security stamp, expire after one day and are not stored. Changing the stamp fails those tokens, and SecurityStampValidator rejects old cookies within 30 minutes.

open as a page

An ASP.NET Core API answers 401 for a JWT that decodes and looks valid; how do you find the cause using IncludeErrorDetails, logging and JwtBearerEvents?

level: seniorimportance: should knowfreq 52%

basics

~10 s

Read the 401's WWW-Authenticate header: IncludeErrorDetails, on by default, adds error="invalid_token" and a reason. Then let Microsoft.AspNetCore.Authentication log at Information, or read context.Exception in JwtBearerEvents.OnAuthenticationFailed.

open as a page

In ASP.NET Core's JwtBearer handler, why does User.FindFirst("sub") return null for a token that has a sub claim, and what changes with MapInboundClaims = false?

level: seniorimportance: should knowfreq 44%

basics

~10 s

JwtBearerOptions.MapInboundClaims defaults to true, so short JWT claim names are renamed to long ClaimTypes URIs: sub becomes ClaimTypes.NameIdentifier. Setting it to false keeps the JWT names, and then NameClaimType and RoleClaimType must name them.

open as a page

In ASP.NET Core 10, how do you put a single-page app behind a BFF that signs in with AddOpenIdConnect so the browser never holds an access token?

level: seniorimportance: should knowfreq 40%

basics

~20 s

The ASP.NET Core host is the OpenID Connect client: it signs in with AddOpenIdConnect, keeps the tokens in its encrypted cookie via SaveTokens and attaches the access token to downstream calls itself. The SPA only ever sends that cookie to same-origin endpoints.

open as a page

In ASP.NET Core 10's OpenIdConnectOptions, which defaults must change for the authorization code flow, and what do UsePkce and PushedAuthorizationBehavior then do?

level: seniorimportance: should knowfreq 45%

basics

~20 s

OpenIdConnectOptions.ResponseType defaults to id_token, so you set it to code and usually supply ClientSecret. PKCE then happens automatically, since UsePkce defaults to true, and since ASP.NET Core 9 the handler pushes the request via PAR whenever the provider advertises it.

open as a page

With the dotnet user-jwts command, how do you test a JWT-protected ASP.NET Core API locally, and what does the command write into your project?

level: middleimportance: nice to knowfreq 24%

basics

~10 s

dotnet user-jwts create issues a signed development token, stores its signing key in the project's user secrets and writes the issuer and audiences under Authentication:Schemes:Bearer in appsettings.Development.json, which AddJwtBearer binds automatically.

open as a page

What passkey support does ASP.NET Core Identity add in .NET 10, and what must an existing Identity app change to store and use passkeys?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

ASP.NET Core 10 Identity adds passkey registration and sign-in through SignInManager and UserManager. An existing app must set Stores.SchemaVersion to IdentitySchemaVersions.Version3, migrate to get the AspNetUserPasskeys table, and build its own passkey pages and endpoints.

open as a page