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

GraphQLLocalExecutionClient: Add user credentials/token #582

Open
StefanKoenigMUC opened this issue Jul 3, 2023 · 6 comments
Open

GraphQLLocalExecutionClient: Add user credentials/token #582

StefanKoenigMUC opened this issue Jul 3, 2023 · 6 comments

Comments

@StefanKoenigMUC
Copy link

Hi there,

for querying a local instance of my graphql instance I'm using the GraphQLLocalExecutionClient. But for specific reasons, I also need to provide user details (username, credentials, ..) for the execution/permissions checks.

Is that somehow possible, without falling back to the HTTP client?

Thanks in advance for your help :-)

@rose-a
Copy link
Collaborator

rose-a commented Jul 3, 2023

GraphQLLocalExecutionClient directly passes the request to a IDocumentExecuter instance of GraphQL.NET (which is injected through the constructor of GraphQLLocalExecutionClient).

You need to find out in which way your GraphQL "instance" expects to receive the user details (remember, the Authorization HTTP header is a transport thing not directly related to the GraphQL engine). graphql-dotnet/server uses this validation rule, which won't work with the local execution client since this does not execute the request in a ASP.Net Core pipeline.

To test GraphQL authorization in an HTTP context I would recommend to actually use a http connection (see integration tests in this repo for some examples). Otherwise you need to build your own validation system, there are some pointers in the GraphQL.NET documentation regarding this topic.

@StefanKoenigMUC
Copy link
Author

hmm so basically i don't need authentication, passing an additional object would be totally fine for me (-> as I'm already within the application context, I have the authenticated user already - just need the user somehow accessible within the query itself).

Thanks a lot for your answer!

@StefanKoenigMUC
Copy link
Author

thanks a lot, did it now using the variable section. Not very nice but working for now :-) Thanks a lot again!

@StefanKoenigMUC
Copy link
Author

hmm still a strange problem

        var graphqlRequest = new GraphQLRequest(request.Query, new
        {
            userName = user.LoginName
        });

        graphqlRequest.Variables = new { id = "foo" };
        graphqlRequest.Extensions = new { id = "foo" };

Variables doesnt show up on server side - Extension is filled properly (problem exists indepent of serializer - tried newtonsoft and system.text). Do you have an idea?

@rose-a
Copy link
Collaborator

rose-a commented Jul 3, 2023

thanks a lot, did it now using the variable section. Not very nice but working for now :-) Thanks a lot again!

I'd recommend using the extensions map for that

Variables doesnt show up on server side - Extension is filled properly (problem exists indepent of serializer - tried newtonsoft and system.text). Do you have an idea?

What is showing up? I'd expect variables to be { "id": "foo" }...

@StefanKoenigMUC
Copy link
Author

What is showing up? I'd expect variables to be { "id": "foo" }...

Nothing, the variables enumerator is empty

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

2 participants