MCPcopy
hub / github.com/fastapi/fastapi / get_current_user

Function get_current_user

docs_src/security/tutorial004_py310.py:92–109  ·  view source on GitHub ↗
(token: str = Depends(oauth2_scheme))

Source from the content-addressed store, hash-verified

90
91
92async def get_current_user(token: str = Depends(oauth2_scheme)):
93 credentials_exception = HTTPException(
94 status_code=status.HTTP_401_UNAUTHORIZED,
95 detail="Could not validate credentials",
96 headers={"WWW-Authenticate": "Bearer"},
97 )
98 try:
99 payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
100 username = payload.get("sub")
101 if username is None:
102 raise credentials_exception
103 token_data = TokenData(username=username)
104 except InvalidTokenError:
105 raise credentials_exception
106 user = get_user(fake_users_db, username=token_data.username)
107 if user is None:
108 raise credentials_exception
109 return user
110
111
112async def get_current_active_user(current_user: User = Depends(get_current_user)):

Callers

nothing calls this directly

Calls 5

DependsClass · 0.90
HTTPExceptionClass · 0.90
TokenDataClass · 0.70
get_userFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…