📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How would you return a ProblemDetails response with a safe reason when authorisation fails, instead of a bare 403?

Mid-Level Coding Intermediate

🎯 Key points

  • IAuthorizationMiddlewareResultHandler customises the response; delegate to AuthorizationMiddlewareResultHandler for defaults
  • Read PolicyAuthorizationResult.AuthorizationFailure.FailureReasons when Forbidden is true
  • Map known reasons to ProblemDetails with Status 403, a stable documented type URI, a title and a user-actionable detail
  • Unknown reasons: generic 403 ProblemDetails, never internal rule or policy names
  • Write through IProblemDetailsService and include traceId so support can correlate with logs
  • Log full failure detail server-side (policy, requirement, user, tenant); keep client messages coarse
  • Keep 401 challenges on the default path (WWW-Authenticate, cookie redirects)

⏱ 30-second answer

Implement IAuthorizationMiddlewareResultHandler, wrap the default AuthorizationMiddlewareResultHandler, and when authorizeResult.Forbidden is true inspect AuthorizationFailure.FailureReasons. Map each known reason to a stable ProblemDetails: Status = 403, a documented type URI (for example https://errors.example.com.au/tenant-suspended), a short title ("Subscription suspended") and a user-friendly detail that tells the user what to do, plus the traceId. Write it with IProblemDetailsService so it matches your other errors. Log the full reason server-side (requirement, policy, user and tenant ids) and keep the client message coarse, so you help legitimate users without telling an attacker which rule to get around. Unknown reasons get a generic 403 problem; 401 challenges stay on the default path so cookie redirects and WWW-Authenticate headers still work.

🔍 What the interviewer is checking

Checks they know IAuthorizationMiddlewareResultHandler and avoid leaking internal detail

↩ Usually asked after

More in Authorization

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me