You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the @require_token and @require_scope decorators in dataone-auth are tightly coupled to Flask. They rely on Flask's global request object (to check request.method and extract headers) and flask.g (to store user context).
To make this library framework-agnostic and usable by both Flask and FastAPI, we need to strip the web-framework routing and request handling out of the shared code.
Changes needed
Modify the shared library to expose a pure Python function, e.g., _validate_and_extract_claims(auth_header: str) -> tuple. This function should take the raw authorization header as a string and return the validated claims (or an error tuple).
Delete the @require_token and @require_scope decorators from the shared library entirely.
the important bit... Implement in Host Apps:
Flask: Include the @require_token and @require_scopes decorators inside the Flask (vegbank) codebase that extracts the header, calls the shared library function, and stores the result via _store_user_context which was also removed.
FastAPI: Create a standard FastAPI dependency (Depends(get_current_user)) in the FastAPI codebase that does the same thing.
Implementation in vegbank is pretty easy, just add the code back in that we stripped out here. FastAPI is a little different, but might look something like this:
Currently, the
@require_tokenand@require_scopedecorators indataone-authare tightly coupled to Flask. They rely on Flask's globalrequestobject (to checkrequest.methodand extract headers) andflask.g(to store user context).To make this library framework-agnostic and usable by both Flask and FastAPI, we need to strip the web-framework routing and request handling out of the shared code.
Changes needed
_validate_and_extract_claims(auth_header: str) -> tuple. This function should take the raw authorization header as a string and return the validated claims (or an error tuple).@require_tokenand@require_scopedecorators from the shared library entirely.@require_tokenand@require_scopesdecorators inside the Flask (vegbank) codebase that extracts the header, calls the shared library function, and stores the result via_store_user_contextwhich was also removed.Depends(get_current_user)) in the FastAPI codebase that does the same thing.Implementation in vegbank is pretty easy, just add the code back in that we stripped out here. FastAPI is a little different, but might look something like this:
Writing this down here mostly for future reference so I don't forget how the implementation is supposed to go later