Home / Function/ get_current_user() — fastapi Function Reference

get_current_user() — fastapi Function Reference

Architecture documentation for the get_current_user() function in tutorial004_an_py310.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  1828521f_d78b_26dd_fe17_751f66e8cd99["get_current_user()"]
  9d9e2d01_cc0e_cfd3_4273_dc6e5f2def65["tutorial004_an_py310.py"]
  1828521f_d78b_26dd_fe17_751f66e8cd99 -->|defined in| 9d9e2d01_cc0e_cfd3_4273_dc6e5f2def65
  4049a822_4e12_48e5_9dc7_06df5b42e6c0["get_user()"]
  1828521f_d78b_26dd_fe17_751f66e8cd99 -->|calls| 4049a822_4e12_48e5_9dc7_06df5b42e6c0
  style 1828521f_d78b_26dd_fe17_751f66e8cd99 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

docs_src/security/tutorial004_an_py310.py lines 90–107

async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
    credentials_exception = HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Could not validate credentials",
        headers={"WWW-Authenticate": "Bearer"},
    )
    try:
        payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
        username = payload.get("sub")
        if username is None:
            raise credentials_exception
        token_data = TokenData(username=username)
    except InvalidTokenError:
        raise credentials_exception
    user = get_user(fake_users_db, username=token_data.username)
    if user is None:
        raise credentials_exception
    return user

Domain

Subdomains

Calls

Frequently Asked Questions

What does get_current_user() do?
get_current_user() is a function in the fastapi codebase, defined in docs_src/security/tutorial004_an_py310.py.
Where is get_current_user() defined?
get_current_user() is defined in docs_src/security/tutorial004_an_py310.py at line 90.
What does get_current_user() call?
get_current_user() calls 1 function(s): get_user.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free