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
The generated function supports the bearer token but not cookie.
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
# retrieve the bearer token from the header
# and save it for use in the AuthClient
authorization = request.headers.get('Authorization')
if authorization:
set_authentication_token(authorization)
return await call_next(request)
The cookie authentication is handy when the application is secured by a gatekeeper, as it comes for free on every request.
It's also ignoring the parameter coming from the spec, like in
This is not necessarily required as we don't have different decode token handlers, but can be confusins as the Connexion apis require those instead
The text was updated successfully, but these errors were encountered:
filippomc
changed the title
Fastapi generated api do not get authentication parameters
Fastapi generated api do not get authentication parameters from Cookie
Sep 23, 2022
To use the cookie in place of the Bearer can change the main.jinja2 template to use the APIKeyCookie in place of the Bearer authentication
Relevant code:
...
fromfastapi.securityimportAPIKeyCookie, HTTPBasicCredentials
...
@app.middleware("http")asyncdefadd_process_time_header(request: Request, call_next):
# retrieve the bearer token from the header# and save it for use in the AuthClientauthorization=request.headers.get('Authorization') orrequest.cookies.get(
'kc-access'
)
ifauthorization:
if"Bearer"inauthorization:
authorization=authorization.split("Bearer ")[1]
set_authentication_token(authorization)
returnawaitcall_next(request)
security=APIKeyCookie(name="kc-access")
The generated function supports the bearer token but not cookie.
The cookie authentication is handy when the application is secured by a gatekeeper, as it comes for free on every request.
It's also ignoring the parameter coming from the spec, like in
This is not necessarily required as we don't have different decode token handlers, but can be confusins as the Connexion apis require those instead
The text was updated successfully, but these errors were encountered: