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

Get Context inside AuthenticatorService.... #307

Open
Kapsonfire-DE opened this issue Oct 17, 2020 · 8 comments
Open

Get Context inside AuthenticatorService.... #307

Kapsonfire-DE opened this issue Oct 17, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@Kapsonfire-DE
Copy link

I'm using graphqlite in a standalone server process (currently reactphp, maybe switching to swoole) and therefore I cant use global variables, so I took my meta data from the request into the context variable passed to executeQuery.

Is there any way to get the context variable inside the AuthenticationServiceInterface/AuthorizationServiceInterface without using a dirty debug_backtrace() hack?

@moufmouf
Copy link
Member

Ouch, excellent question.

Currently, there is no way, but you are completely right, we need to be able to do this.

Do you think we should pass the context variable, or maybe directly a PSR-7 Request object?

I don't have to much time to work on this right now, but I would gladly accept a pull request!

@Kapsonfire-DE
Copy link
Author

I tested a little bit - at current state the auth function is just called once (cached). Because of this, I need to create the schema for each request new.

So we need either remove the cache (maybe a flag) or cache by a pseudo unique identifier, like a session id which has to be passed in some way. For my case, disable Authentication Cache is enough, the Authorization Cache can be easily mapped by the user object returned by Authentication Service.

To answer your question.
Passing the context to every function after executeQuery should be done.
The programmer itself is free to add there the Request in his own format or as PSR 7 request.

@moufmouf
Copy link
Member

Damn, I did not think about the caching, you are completely right!

Caching happens here:

https://github.com/thecodingmachine/graphqlite/blob/master/src/Middlewares/AuthorizationFieldMiddleware.php#L60-L62

The authentication is done only once and if it succeeds, the field is part of the schema.

What we could do is use the same strategy as the "@Security" annotation:

https://github.com/thecodingmachine/graphqlite/blob/master/src/Middlewares/SecurityFieldMiddleware.php#L86-L92

Here, the resolver is wrapped into another resolver that is called each time a field is resolved. That would solve your issue.

Otherwise, 👍 for passing the context. It makes sense.

@fezfez
Copy link
Contributor

fezfez commented May 28, 2023

Hello ! Any news on this, if you was able to achieve this, can you provide an example? Thanks !

@oojacoboo
Copy link
Collaborator

@fezfez there have been some more recent efforts to get GraphQLite working with a long running server by eliminating immutability. Please see: #584

Is this your objective, or are you specifically referring to accessing the Context?

@fezfez
Copy link
Contributor

fezfez commented May 30, 2023

Yep a was trying to use swoole in my apps, this is the last step to go in production.

@oojacoboo
Copy link
Collaborator

oojacoboo commented May 31, 2023

There was some conversation around getting more lazy loading around authentication for this purpose I believe. I don't really recall the full status on those efforts. There are some PRs that need to be merged and some other efforts. I believe @oprypkhantc was working on these.

@oprypkhantc
Copy link
Contributor

It'd be nice for it to get PRs reviewed @oojacoboo :) But yes, besides my changes there are other things to be done - like using a new context instance for every request, and possibly making that accessible throughout GraphQLite. That's not as easy as it sounds though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants