graphql-dotnet / graphql-dotnet/authorization

How to read graphql query from authorization requirement ?

Open
#268 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
160
Forks
38
PR merge metrics
No merged PRs in 30d

Description

I am using graphql-dotnet in dotnet 6, Need to get argument from the query/mutation for authentication. In AuthorizationHandler how to extract the values from query.

This is a sample query

```
{
formQuery {
form(id: 1, organisationId: "string") {
id
name
organisationId
}
}
}

```

How to parse `formId` and `organisationId` from query?

This is my implementation

```
public class ValidOrganisationHandler : AuthorizationHandler
{
private readonly IHttpContextAccessor _httpContextAccessor;

public ValidOrganisationHandler(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}

protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context,
ValidOrganisationRequirement requirement)
{
if (_httpContextAccessor.HttpContext != null)
{
// How to get value from graphql query/mutation

if (/*parsed value*/)
{
context.Succeed(requirement);
}
else
{
context.Fail();
}
}
else
{
context.Fail();
}

context.Succeed(requirement);
// return Task.CompletedTask;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.