get_current_user() — fastapi Function Reference
Architecture documentation for the get_current_user() function in tutorial005_an_py310.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 4498cb6c_3238_da2f_019a_df733a97d763["get_current_user()"] 8a0ba17a_1db0_9446_2cfd_cfd18d89c608["tutorial005_an_py310.py"] 4498cb6c_3238_da2f_019a_df733a97d763 -->|defined in| 8a0ba17a_1db0_9446_2cfd_cfd18d89c608 870353d8_c302_a311_913c_b00a1c6d1076["get_user()"] 4498cb6c_3238_da2f_019a_df733a97d763 -->|calls| 870353d8_c302_a311_913c_b00a1c6d1076 style 4498cb6c_3238_da2f_019a_df733a97d763 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
docs_src/security/tutorial005_an_py310.py lines 105–137
async def get_current_user(
security_scopes: SecurityScopes, token: Annotated[str, Depends(oauth2_scheme)]
):
if security_scopes.scopes:
authenticate_value = f'Bearer scope="{security_scopes.scope_str}"'
else:
authenticate_value = "Bearer"
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": authenticate_value},
)
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
username = payload.get("sub")
if username is None:
raise credentials_exception
scope: str = payload.get("scope", "")
token_scopes = scope.split(" ")
token_data = TokenData(scopes=token_scopes, username=username)
except (InvalidTokenError, ValidationError):
raise credentials_exception
user = get_user(fake_users_db, username=token_data.username)
if user is None:
raise credentials_exception
for scope in security_scopes.scopes:
if scope not in token_data.scopes:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Not enough permissions",
headers={"WWW-Authenticate": authenticate_value},
)
return user
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does get_current_user() do?
get_current_user() is a function in the fastapi codebase, defined in docs_src/security/tutorial005_an_py310.py.
Where is get_current_user() defined?
get_current_user() is defined in docs_src/security/tutorial005_an_py310.py at line 105.
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