AuthorizeAttribute when used in mutation/ query class level is overwritten to other mutations
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
When a mutation is extended with [ExtendObjectType(typeof(Mutation)] and all mutations have the [Authorize(Roles = new[] "Avenger")] attribute, the user will get an Authorization exception if he is not in all roles
Steps to reproduce
- Add user to role
claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, "Skye");
- Register
services.AddGraphQLServer()
.AddConvention<INamingConventions>(new SameNameConventions())
.AddAuthorization()
.AddMutationType<Mutation>()
.AddTypeExtension<TestBaseResolver>()
.AddTypeExtension<TestResolver>()
- Build TestBaseResolver
using HotChocolate.AspNetCore.Authorization;
[ExtendObjectType(typeof(Mutation))]
[Authorize(Roles = new[] { "Ryder" })]
public class TestBaseResolver
{
public string GetTestMessage()
{
return "Done Test Message";
}
}
- Build TestResolver
using HotChocolate.AspNetCore.Authorization;
[ExtendObjectType(typeof(Mutation))]
[Authorize(Roles = new[] { "Chase", "Skye" })]
public class TestResolver
{
public string GetTestMessage()
{
return "Done Test Message";
}
}
When you now call the TestResolver GetTestMessage you get an unauth exception.
Relevant log output
No response
Additional Context?
I understand AuthorizeAttribute when used in class level that it applies to the entire ExtendObjectType. However, in this scenario it seems that the roles are not combined but overwritten. The issue does not exists of cause when I apply the Authorizse-Attribute on Method-Level.
Product
Hot Chocolate
Version
13.0.0-preview.70
That is actually correct.
directives annotated on the type extensions are just applied to the overall type .... its not scoped.
We will be overhauling authentication and are at the moment in planing stage... but for the current implementation that is correct.