-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
inject_user() and graphql views. #161
Comments
You are right, you could get it by decoding the token yourself. But, you also should be able to get it with
Where, I am not 100% sure about I can try and dig in and take a look. |
So the place that from sanic import Sanic
from sanic_jwt import Initialize
from sanic_graphql import GraphQLView
import graphene
user = {"user_id": 1, "username": "foobar"}
app = Sanic(__name__)
sanicjwt = Initialize(
app, authenticate=lambda x: user, retrieve_user=lambda x, y: user
)
class Query(graphene.ObjectType):
hello = graphene.String(argument=graphene.String(default_value="stranger"))
def resolve_hello(self, info, argument):
return "Hello " + argument
schema = graphene.Schema(query=Query)
class AuthorizationMiddleware:
def resolve(next, root, info, **args):
print("AuthorizationMiddleware.resolve:\n=============")
print(f"\troot: {root}")
print(f"\tinfo: {info}")
print(f"\targs: {args}")
return next(root, info, **args)
class SanixGraphql(GraphQLView):
schema = schema
graphiql = True
decorators = [sanicjwt.protected(), sanicjwt.inject_user()]
middleware = [AuthorizationMiddleware]
async def dispatch_request(self, *args, **kwargs):
print("SanixGraphql.dispatch_request:\n=============")
print(f"\targs: {args}")
print(f"\tkwargs: {kwargs}")
return await super().dispatch_request(*args, **kwargs)
app.add_route(SanixGraphql.as_view(), "/graphql")
if __name__ == "__main__":
app.run(debug=True) This is the barebones test that I was running just to see what is going on.
As you can see, What is is you are trying to achieve so I can help understand what the goal is. |
Basically I want to have easy access to the |
Hello, I'm looking for a way to use
inject_user()
on a class based GraphQL view, or some other way to access the user_id. I have the following PoC for GraphQL, and I can inject a user object into the**args
parameter, but there does not seem to be any easily exposed functions in the library that allows me to quickly pull out a claim without parsing stuff myself.Is there anything I can use to easily extract the
user_id
from the token inside the AuthorizationMiddleware.resolve`method.The text was updated successfully, but these errors were encountered: