graphql-client
graphql-client copied to clipboard
GraphQLLocalExecutionClient: Add user credentials/token
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 :-)
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.
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!
thanks a lot, did it now using the variable section. Not very nice but working for now :-) Thanks a lot again!
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?
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" }...
What is showing up? I'd expect variables to be { "id": "foo" }...
Nothing, the variables enumerator is empty