Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom AuthorizationHandler HandleRequirementAsync when context fails HC returns AUTH_NOT_AUTHENTICATED instead of AUTH_NOT_AUTHORIZED #7779

Open
cli00004 opened this issue Nov 28, 2024 · 2 comments

Comments

@cli00004
Copy link

Product

Hot Chocolate

Version

14

Link to minimal reproduction

na

Steps to reproduce

I have a custom Authorization handler, and in HandleRequirementAsync, I have my custom authorization logic, when authorization fails, context.Fail() is called, standard asp.net process to handle authorization policy requirement. But when this happens, hotchocolate gives AUTH_NOT_AUTHENTICATED instead of AUTH_NOT_AUTHORIZED error code, in HC 13 it was returning AUTH_NOT_AUTHORIZED. This is about authorization not authentication, the user is already authenticated by the role does not pass the authorization policy to access the info. Does it sound like a bug or is it by design?

What is expected?

AUTH_NOT_AUTHORIZED should be returned when AuthorizationHandler fails the authrozation check, i.e. revert back to behaviour in HC 13

What is actually happening?

I have a custom Authorization handler, and in HandleRequirementAsync, I have my custom authorization logic, when authorization fails, context.Fail() is called, standard asp.net process to handle authorization policy requirement. But when this happens, hotchocolate gives AUTH_NOT_AUTHENTICATED instead of AUTH_NOT_AUTHORIZED error code, in HC 13 it was returning AUTH_NOT_AUTHORIZED. This is about authorization not authentication, the user is already authenticated by the role does not pass the authorization policy to access the info. Does it sound like a bug or is it by design?

Relevant log output

Additional context

No response

@michaelstaib
Copy link
Member

We need a repro for this.

@cli00004
Copy link
Author

cli00004 commented Dec 3, 2024

Here's the handler,

public class GraphQlAuthorizationHandler : AuthorizationHandler<OpaRequirement, IResolverContext>
 {


   protected override async Task HandleRequirementAsync(
     AuthorizationHandlerContext context,
     OpaRequirement requirement,
     IResolverContext resource)
   {

       if (someCustomAuthorisationCheck == true)
         context.Succeed((IAuthorizationRequirement) requirement);
       else
         context.Fail();
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants