ChilliCream / ChilliCream/graphql-platform

Accessing AuthorizationFailureReason in policy based auth

Open
#6,442 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Authorization
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Is your feature request related to a problem?

If using policy based auth with IAuthorizationHandler interface, there is a option to pass instance of AuthorizationFailureReason to the Fail method of AuthorizationHandlerContext. This object might contain futher details about failed auhtoirazion.

When HC returns unauthorized response it looks like this:
{ "errors": [ { "message": "The current user is not authorized to access this resource.", "locations": [ { "line": 2, "column": 3 } ], "path": ["welcome"], "extensions": { "code": "AUTH_NOT_AUTHENTICATED" } } ], "data": { "welcome": null } }

The solution you'd like

Include AuthorizationFailureReason.Message in the response or at least log it somewhere.

As of now there is only propert Succeeded of AuthorizationResult being used in DefaultAuthorizationHandler. Content of property Filaure of type AuthorizationFailure which holds AuthorizationFailureReasons and list of failed IAuhtoirazionRequirements is currently completely ignored.

Debugging system with dozens of auth requirements is pain when you have to debug the code in order to figure out which of the requirements was not met.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading DefaultAuthorizationHandler and trace how AuthorizationResult uses Succeeded while ignoring Failure, AuthorizationFailureReasons, and failed IAuthorizationRequirements. Determine the existing authorization response or logging entry point, then define completion as making AuthorizationFailureReason.Message available in the response or logging it without exposing inappropriate details.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, graphql
Domain
api, authorization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.