Login and get access token.
(form_data: OAuth2PasswordRequestForm = Depends())
| 137 | |
| 138 | @router.post("/token", response_model=Token) |
| 139 | async def login(form_data: OAuth2PasswordRequestForm = Depends()): |
| 140 | """Login and get access token.""" |
| 141 | user = authenticate_user(form_data.username, form_data.password) |
| 142 | if not user: |
| 143 | raise HTTPException( |
| 144 | status_code=status.HTTP_401_UNAUTHORIZED, |
| 145 | detail="Incorrect username or password", |
| 146 | headers={"WWW-Authenticate": "Bearer"}, |
| 147 | ) |
| 148 | access_token_expires = timedelta(hours=settings.JWT_EXPIRATION_HOURS) |
| 149 | access_token = create_access_token( |
| 150 | data={"sub": user.username}, |
| 151 | expires_delta=access_token_expires |
| 152 | ) |
| 153 | return {"access_token": access_token, "token_type": "bearer"} |
| 154 | |
| 155 | @router.get("/me", response_model=User) |
| 156 | async def read_users_me(current_user: User = Depends(get_current_active_user)): |
nothing calls this directly
no test coverage detected