liveBook · Manning

Challenge response

As explained in ASP.NET Core in Action, 3e

A challenge response indicates that a request failed authorization because the user is not authenticated.

A challenge response means a request failed authorization because the user is not authenticated. AuthorizationMiddleware stops the request instead of executing the protected endpoint. section 24.2.2

Separate a challenge from the other authorization outcomes:

  • Challenge: the user has not logged in and must authenticate. section 24.2.2
  • Forbid: the user is authenticated but lacks a required authorization condition, such as a claim. section 24.2.2
  • Success: the request passes through authorization and the endpoint executes. section 24.2.2

Cookie-authenticated web application

When a user requests a protected Razor Page without authentication, a cookie-authentication challenge redirects the user to the application’s login page. After logging in, the user can try the protected resource again. section 24.2.2

Figure 24.3 The three types of response to an authorization attempt. In the left example, the request contains an authentication cookie, so the user is authenticated in the AuthenticationMiddleware. The AuthorizationMiddleware confirms that the authenticated user can access the selected endpoint, so the endpoint is executed. In the center example, the request is not authenticated, so the Authorization-Middleware generates a challenge response. In the right example, the request is authenticated, but the user does not have permission to execute the endpoint, so a forbid response is generated.
CH24_F03_Lock3

Compare successful authorization, a challenge for an unauthenticated request, and a forbid response for an authenticated user without permission. section 24.2.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines the outcome and middleware behavior, then contrasts cookie redirects without specifying API response formats.
Examples
Uses a protected Razor Page requested without authentication and redirected to a login page.
What it assumes
Assumes endpoint authorization and authentication concepts while distinguishing unauthenticated users from authenticated users without permission.
What you can do after
Evaluate whether authorization failed because a user is unauthenticated or lacks permission.
How it connects
Connects authentication, authorization requirements, AuthorizationMiddleware, endpoint execution, cookie authentication, and forbid responses.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.