Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read graphql query from authorization requirement ? #268

Open
bannarisoftwares opened this issue Jun 29, 2023 · 0 comments
Open

How to read graphql query from authorization requirement ? #268

bannarisoftwares opened this issue Jun 29, 2023 · 0 comments

Comments

@bannarisoftwares
Copy link

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;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant