-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add authorization for user GraphQL endpoints #14
Conversation
Did some front-end testing by adding planet-read/backend/python/app/graphql/mutations/auth_mutation.py Lines 38 to 44 in 01e8a7f
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Fun fact: you can also get the jwt token via curl request, see Jenn's file PR (#8 )
Regarding using Headers for graphql requests, unfortunately, you're correct that graphiql doesn't support this. As far as I know, Postman should be fine. Personally, I installed Altair on to chrome and set the header Authorization
to Bearer <token>
with no problems.
Let's skip require_authorization_by_user_id
for now.
Can you docker-compose down and up and try the front-end testing with |
hm I tried again and got the same behaviour. The GraphQL endpoint wasn't causing the problem, it's that it's querying refresh so I can't fully test it. What happened for you when you clicked the "Reset Password" button when not logged in? |
Only tested the endpoint from the backend. Good to know that this is an issue - I think you're good to rebase and squash and we can test again once the refresh endpoint is done. |
85498c4
to
3707ec4
Compare
Notion ticket link
Add authorization checks to Graphql resolvers
Implementation description
require_authorization_by_role_gql
that performs the same checks as its non-GraphQL equivalent. Needed to change the arguments and how it accessed headers (request object is ininfo.context
rather than justrequest
)schema.py
) based on https://graphql.org/learn/authorization/Also, I added the method into the existing
auth.py
instead of creating a new file because when we eliminate the REST code, the file name still makes sense and now requires a single method name refactor.Steps to test
Setup -> I added users manually (see #11). Not really necessary, but makes for slightly more interesting testing 🤷
localhost:5000/graphql
and mess around with any of the queries and any of the mutations except forresetPassword
. Should respond that "You are not authorized to make this request.", eg. below. Can also produce this in Postman if you have no/an incorrectAuthorization
header.console.log(window.localStorage.getItem("localhost:AUTHENTICATED_USER"));
in front-end console. Use this (formatted asBearer <access-token>
) as theAuthorization
header and try making any of the above failing requests. Should return as expected, no errors. I used Postman for this.What should reviewers focus on?
require_authorization_by_user_id
? No way to test without logout GraphQL endpoint being establishedChecklist
docker exec -it <backend-container-id> /bin/bash -c "black . && isort --profile black ."