Skip to content

How to read graphql query from authorization requirement ? #268

Description

@bannarisoftwares

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<ValidOrganisationRequirement>
{
    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;
    }

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions