get_current_user() — fastapi Function Reference
Architecture documentation for the get_current_user() function in tutorial005_py310.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD b9ac9b96_fbcf_3ba1_e48c_98672c399c2c["get_current_user()"] 66858a25_944d_cbf6_b313_ab09e0ce6572["tutorial005_py310.py"] b9ac9b96_fbcf_3ba1_e48c_98672c399c2c -->|defined in| 66858a25_944d_cbf6_b313_ab09e0ce6572 6239c862_0f74_dac0_6d7f_a44eef6a96a0["get_user()"] b9ac9b96_fbcf_3ba1_e48c_98672c399c2c -->|calls| 6239c862_0f74_dac0_6d7f_a44eef6a96a0 style b9ac9b96_fbcf_3ba1_e48c_98672c399c2c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
docs_src/security/tutorial005_py310.py lines 104–136
async def get_current_user(
security_scopes: SecurityScopes, token: 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: str = 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_py310.py.
Where is get_current_user() defined?
get_current_user() is defined in docs_src/security/tutorial005_py310.py at line 104.
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