Added API Token Verification to lock restricted calls #182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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).
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