DefaultAuthorizationHandler does not use policy-bound authentication schemes #6450
Replies: 2 comments
-
I've just tried updating HotChocolate version up to 13.4.0. |
Beta Was this translation helpful? Give feedback.
-
Hello, Thank you in advance for the response |
Beta Was this translation helpful? Give feedback.
-
Is there an existing issue for this?
Product
Hot Chocolate
Describe the bug
In my project I've configured two custom auth schemes, one that requires ApiKey, and the second one that requires both ApiKey and Bearer JWT provided (let's call it "BearerWithApiKey"), then I control allowed schemes using Policies.
Both were registered using Microsoft's AddScheme<Options, Handler>() method with UseAuthentication() with no default scheme provided, because these are configured explicitly on each policy.
Repro shows the general configuration process.
While it works perfectly fine for standard .NET HTTP requests, HotChocolate seems unable to determine Authentication Scheme based purely on policy and its attached Authentication Schemes, instead it seems to only pick up the AddAuthentication("DefaultSchemeHere") from Program.cs, otherwise it just fails to authenticate the user.
What I've tried, but failed to make it work:
There is not enough data in HttpContext, RequestExecutor or Builder to determine Policy and/or Scheme that is bound to current context.
Maybe applying custom directives and then mapping them to auth schemes would yield some results, but somehow it seems like a hacky way to do things and it requires more maintenance, assuming I could properly find and match the directives in IRequestExecutor.Schema.Directives.
Potential solutions:
While it mixes both Authentication and Authorization processes, that way I can still use Authorization schemes divided per Policy.
The code below is a POC representation of the idea:
I've provided some example code in repro, let me know if full example project is necessary to evaluate the problem.
Steps to reproduce
Execute a request with any policy specified:
Scheme-specific handlers will never run and standard 401 HotChocolate response occurs:
Relevant log output
No response
Additional Context?
No response
Version
13.0.5, 13.4.0
Beta Was this translation helpful? Give feedback.
All reactions