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

Added API Token Verification to lock restricted calls #182

Merged
merged 4 commits into from
Feb 27, 2024
Merged

Conversation

ansengarvin
Copy link
Collaborator

@ansengarvin ansengarvin commented Feb 26, 2024

api_lock_pr_small.mp4

I implemented basic token sending and validation between the frontend and the backend. To do this, I implemented two simple
functions:

  1. Frontend: setToken(). This function automatically looks at the authentication cookie, and sets the OpenAPI authorization header to the bearer token stored in that cookie. Meant to be placed right before making a restricted call (e.g. inside of a button's onSubmit).

  2. Backend: requireAuthentication(req). This takes in a FastAPI Request object and validates the token header in that object, and ensures that the user giving the token is an admin. Automatically returns 403 Forbidden if the token is invalid or the user is not an admin. Meant to be placed at the top of any restricted API request.

The API calls being locked right now are protein edit, upload, and delete.

The changes present here are not user-facing, so the only real way to test it is to do the above commands and see if they break or not. I also included some print commands which you can see in the backend's log in Docker.. These changes should, in the future, be more extensively-changed

Closes #175
Closes #131
Closes #132
Closes #133

@ansengarvin ansengarvin marked this pull request as ready for review February 26, 2024 05:00
@xnought xnought self-requested a review February 26, 2024 18:10
Copy link
Member

@xnought xnought left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great. Only thing I changed was print() to using the logging library log.warn() just for consistency across the project.

Great job let's merge this

@xnought xnought merged commit 93ea05d into main Feb 27, 2024
2 checks passed
@xnought xnought deleted the api-lock branch February 27, 2024 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants