Wednesday 7 July 2021

FastAPI auth with jwt, but not OAuth2 - is it possible to customize built-in OAuth2PasswordBearer?

On my frontend there is some custom auth flow with jwt, which differs from OAuth2 flow (clearly described in FastAPI docs), only by how credentials are sent to /login endpoint. Frontend makes POST with json in body {"email": "...", "password": "..."} instead of username; password in form data.

Is there some way to customize OAuth2PasswordBearer or some other built-in security class to support this scenario? It will be nice to still have fully-functional SwaggerUI docs with Authorize form etc.

I see there are many recipes, how to support jwt, but most of them are not integrated well with SwaggerUI docs and it will be nice to base solution on some class buit-into FastAPI itself.



from FastAPI auth with jwt, but not OAuth2 - is it possible to customize built-in OAuth2PasswordBearer?

No comments:

Post a Comment