MCPcopy Index your code
hub / github.com/fastapi/fastapi / login_for_access_token

Function login_for_access_token

docs_src/security/tutorial004_py310.py:119–133  ·  view source on GitHub ↗
(
    form_data: OAuth2PasswordRequestForm = Depends(),
)

Source from the content-addressed store, hash-verified

117
118@app.post("/token")
119async def login_for_access_token(
120 form_data: OAuth2PasswordRequestForm = Depends(),
121) -> Token:
122 user = authenticate_user(fake_users_db, form_data.username, form_data.password)
123 if not user:
124 raise HTTPException(
125 status_code=status.HTTP_401_UNAUTHORIZED,
126 detail="Incorrect username or password",
127 headers={"WWW-Authenticate": "Bearer"},
128 )
129 access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
130 access_token = create_access_token(
131 data={"sub": user.username}, expires_delta=access_token_expires
132 )
133 return Token(access_token=access_token, token_type="bearer")
134
135
136@app.get("/users/me/")

Callers

nothing calls this directly

Calls 5

DependsClass · 0.90
HTTPExceptionClass · 0.90
authenticate_userFunction · 0.70
create_access_tokenFunction · 0.70
TokenClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…