graphql-dotnet / graphql-dotnet/authorization
Arguments Empty When Trying Authorize
- Dominant language
- C#
- Stars
- 160
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to authorize a field by validating it´s input arguments in a custom policy. My policy gets executed correctly but the Arguments property of the AuthorizationContext variable is always empty. What do I need to do in order to get this populated?
### Field Definition
```csharp
Field(
name: "deviceContext",
description: "Get device context data by id.",
arguments: new QueryArguments(
new QueryArgument {Name = "id"},
new QueryArgument {Name = "organizationId"}
),
resolve: context => new DeviceContext
{
// my dummy object here
}
).AuthorizeWith();
```
### DeviceQueryPolicy
```csharp
public class DeviceQueryPolicy : IAuthorizationPolicy
{
public DeviceQueryPolicy(IDependencyResolver resolver)
{
Requirements = new[]
{
new DeviceIdMatchOrganizationIdRequirement(resolver),
};
}
public IEnumerable Requirements { get; }
}
```
### DeviceIdMatchOrganizationIdRequirement
```csharp
public async Task Authorize(AuthorizationContext context)
{
// Arguments is always empty here! Why?
if (!context.Arguments.ContainsKey("id")
|| !context.Arguments.ContainsKey("organizationId")) {
context.ReportError("Organization have no access rights to this device");
return;
}
```
### Query
```graphql
# Passing along two arguments
{
devices {
deviceContext(
id: "26748243-9D9D-4E9A-A890-718A46D2C0D5"
organizationId: "26748243-9D9D-4E9A-A890-718A46D2C0D5"
) {
active
}
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.