FastAPI cookie login question #25
-
|
Hi Sam, I worked through your blog How to create a FastAPI Web App with authentication, which is awesome by the way, but there is one thing I don't understand. The endpoint/function, @app.post("token")
def login_for_access_token(
response: Response,
form_data: OAuth2PasswordRequestForm = Depends()
) -> Dict[str, str]:Can be called in two different cases. From a login, where it's called directly with username and password in form_data. It can also be called from a secured endpoint, i.e. "/private", through a dependency. The private endpoint first has a dependency "get_current_user_from_token" which in turn injects "oauth2_scheme" which calls the tokenUrl "token". I've looked through the OAuth classes but, what I don't understand is how "token" gets the form_data in from a secured endpoint. Username and Password is not stored (except username in the token) so where do these come from? Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
I get it....the OAuth2PasswordBearerWithCookie class looks for 'bearer'. It intercepts before it goes to 'token'? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @CJRockball, thanks for reading my blog post and asking the question :) The best explanation can be found on the FastAPI docs: https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/#code-to-get-the-username-and-password. I will take a stab at explaining. The |
Beta Was this translation helpful? Give feedback.
I get it....the OAuth2PasswordBearerWithCookie class looks for 'bearer'. It intercepts before it goes to 'token'?