Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 23 for get_current_active_user (0.11 seconds)

The search processing time has exceeded the limit. The displayed results may be partial.

  1. docs_src/security/tutorial004_an_py310.py

    
    @app.get("/users/me/")
    async def read_users_me(
        current_user: Annotated[User, Depends(get_current_active_user)],
    ) -> User:
        return current_user
    
    
    @app.get("/users/me/items/")
    async def read_own_items(
        current_user: Annotated[User, Depends(get_current_active_user)],
    ):
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 18:10:35 GMT 2026
    - 4.2K bytes
    - Click Count (0)
  2. docs/en/docs/advanced/security/oauth2-scopes.md

    In this case, we pass a dependency function `get_current_active_user` to `Security` (the same way we would do with `Depends`).
    
    But we also pass a `list` of scopes, in this case with just one scope: `items` (it could have more).
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 13.4K bytes
    - Click Count (0)
  3. docs_src/security/tutorial003_an_py310.py

                status_code=status.HTTP_401_UNAUTHORIZED,
                detail="Not authenticated",
                headers={"WWW-Authenticate": "Bearer"},
            )
        return user
    
    
    async def get_current_active_user(
        current_user: Annotated[User, Depends(get_current_user)],
    ):
        if current_user.disabled:
            raise HTTPException(status_code=400, detail="Inactive user")
        return current_user
    
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Mon Nov 24 19:03:06 GMT 2025
    - 2.5K bytes
    - Click Count (0)
  4. docs_src/security/tutorial005_an_py310.py

    
    @app.get("/users/me/")
    async def read_users_me(
        current_user: Annotated[User, Depends(get_current_active_user)],
    ) -> 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"])],
    ):
        return [{"item_id": "Foo", "owner": current_user.username}]
    
    
    @app.get("/status/")
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 18:10:35 GMT 2026
    - 5.4K bytes
    - Click Count (0)
  5. docs_src/security/tutorial003_py310.py

                status_code=status.HTTP_401_UNAUTHORIZED,
                detail="Not authenticated",
                headers={"WWW-Authenticate": "Bearer"},
            )
        return user
    
    
    async def get_current_active_user(current_user: User = Depends(get_current_user)):
        if current_user.disabled:
            raise HTTPException(status_code=400, detail="Inactive user")
        return current_user
    
    
    @app.post("/token")
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Mon Nov 24 19:03:06 GMT 2025
    - 2.4K bytes
    - Click Count (0)
  6. docs/zh-hant/docs/advanced/security/oauth2-scopes.md

    為此,我們從 `fastapi` 匯入並使用 `Security`。
    
    你可以使用 `Security` 來宣告相依性(就像 `Depends`),但 `Security` 也能接收參數 `scopes`,其為 scopes(字串)的列表。
    
    在這裡,我們將相依函式 `get_current_active_user` 傳給 `Security`(就像使用 `Depends` 一樣)。
    
    但同時也傳入一個 `list` 的 scopes,這裡只有一個 scope:`items`(當然也可以有更多)。
    
    而相依函式 `get_current_active_user` 也能宣告子相依性,不只用 `Depends`,也能用 `Security`。它宣告了自己的子相依函式(`get_current_user`),並加入更多 scope 要求。
    
    在這個例子中,它要求 `me` 這個 scope(也可以要求多個)。
    
    /// note
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 12.7K bytes
    - Click Count (0)
  7. docs/zh/docs/advanced/security/oauth2-scopes.md

    再次回顾这个依赖树与作用域。
    
    由于 `get_current_active_user` 依赖把 `get_current_user` 作为子依赖,因此在 `get_current_active_user` 中声明的作用域 `"me"` 会被包含在传给 `get_current_user` 的 `security_scopes.scopes` 所需作用域列表中。
    
    *路径操作*本身也声明了一个作用域 `"items"`,它也会包含在传给 `get_current_user` 的 `security_scopes.scopes` 列表中。
    
    依赖与作用域的层级结构如下:
    
    * *路径操作* `read_own_items` 包含:
        * 带有依赖的必需作用域 `["items"]`:
        * `get_current_active_user`:
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:06:37 GMT 2026
    - 13K bytes
    - Click Count (0)
  8. docs/en/docs/tutorial/security/simple-oauth2.md

    ## Update the dependencies { #update-the-dependencies }
    
    Now we are going to update our dependencies.
    
    We want to get the `current_user` *only* if this user is active.
    
    So, we create an additional dependency `get_current_active_user` that in turn uses `get_current_user` as a dependency.
    
    Both of these dependencies will just return an HTTP error if the user doesn't exist, or if is inactive.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 9.4K bytes
    - Click Count (0)
  9. docs/zh-hant/docs/tutorial/security/simple-oauth2.md

    這幾乎是你為了符合規範而必須自行記得正確處理的唯一事情。
    
    其餘的 **FastAPI** 都會幫你處理。
    
    ///
    
    ## 更新依賴項 { #update-the-dependencies }
    
    接著我們要更新依賴項。
    
    我們只想在使用者為啟用狀態時取得 `current_user`。
    
    所以,我們新增一個依賴 `get_current_active_user`,而它本身又依賴 `get_current_user`。
    
    這兩個依賴會在使用者不存在或未啟用時回傳 HTTP 錯誤。
    
    因此,在端點中,只有在使用者存在、已正確驗證且為啟用狀態時,我們才會取得使用者:
    
    {* ../../docs_src/security/tutorial003_an_py310.py hl[58:66,69:74,94] *}
    
    /// info
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 9.1K bytes
    - Click Count (0)
  10. docs/tr/docs/advanced/security/oauth2-scopes.md

    Bu durumda `Security`'ye dependency fonksiyonu olarak `get_current_active_user` veriyoruz (`Depends` ile yaptığımız gibi).
    
    Ama ayrıca bir `list` olarak scope'ları da veriyoruz; burada tek bir scope var: `items` (daha fazla da olabilir).
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 07:53:17 GMT 2026
    - 14.7K bytes
    - Click Count (0)
Back to Top