|
|
@ -137,7 +137,7 @@ async def get_current_user( |
|
|
|
|
|
|
|
|
|
|
|
async def get_current_active_user( |
|
|
|
current_user: Annotated[User, Security(get_current_user, scopes=["me"])] |
|
|
|
current_user: Annotated[User, Security(get_current_user, scopes=["me"])], |
|
|
|
): |
|
|
|
if current_user.disabled: |
|
|
|
raise HTTPException(status_code=400, detail="Inactive user") |
|
|
@ -146,7 +146,7 @@ async def get_current_active_user( |
|
|
|
|
|
|
|
@app.post("/token") |
|
|
|
async def login_for_access_token( |
|
|
|
form_data: Annotated[OAuth2PasswordRequestForm, Depends()] |
|
|
|
form_data: Annotated[OAuth2PasswordRequestForm, Depends()], |
|
|
|
) -> Token: |
|
|
|
user = authenticate_user(fake_users_db, form_data.username, form_data.password) |
|
|
|
if not user: |
|
|
@ -161,14 +161,14 @@ async def login_for_access_token( |
|
|
|
|
|
|
|
@app.get("/users/me/", response_model=User) |
|
|
|
async def read_users_me( |
|
|
|
current_user: Annotated[User, Depends(get_current_active_user)] |
|
|
|
current_user: Annotated[User, Depends(get_current_active_user)], |
|
|
|
): |
|
|
|
return current_user |
|
|
|
|
|
|
|
|
|
|
|
@app.get("/users/me/items/") |
|
|
|
async def read_own_items( |
|
|
|
current_user: Annotated[User, Security(get_current_active_user, scopes=["items"])] |
|
|
|
current_user: Annotated[User, Security(get_current_active_user, scopes=["items"])], |
|
|
|
): |
|
|
|
return [{"item_id": "Foo", "owner": current_user.username}] |
|
|
|
|
|
|
|