ASP.NET Core Interview Question #129
What is an authentication scheme?
Authentication, Authorization & Security Mid-Level Intermediate
Quick Interview Answer
An authentication scheme is a named configuration that identifies an authentication handler and its options. Applications can have multiple schemes, such as cookies for the web UI and JWT bearer authentication for APIs.
Detailed Explanation
An authentication scheme is a named configuration that identifies an authentication handler and its options. Applications can have multiple schemes, such as cookies for the web UI and JWT bearer authentication for APIs.
Default schemes can define which handler is used for authenticate, challenge, and forbid operations. Explicit scheme selection is useful when different endpoints require different authentication mechanisms.
Code Example
builder.Services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = "AppCookie";
options.DefaultChallengeScheme = "AppCookie";
})
.AddCookie("AppCookie");