INNER CODE UNIT · Python
get_user
dorinclisu/fastapi-auth0 · src/fastapi_auth0/auth.py:108
async def get_user(self,
security_scopes: SecurityScopes,
creds: Optional[HTTPAuthorizationCredentials] = Depends(Auth0HTTPBearer(auto_error=False)),
) -> Optional[Auth0User]:
"""
Verify the Authorization: Bearer token and return the user.
If there is any problem and auto_error = True then raise Auth0UnauthenticatedException or Auth0UnauthorizedException,
otherwise return None.
Not to be called directly, but to be placed within a Depends() or Security() wrapper.
Example: def path_op_func(user: Auth0User = Security(auth.get_user)).
"""
if creds is None:
if self.auto_error:
# See HTTPBearer from FastAPI:
# latest - https://github.com/tiangolo/fastapi/blob/master/fastapi/security/http.py
# 0.65.1 - https://github.com/tiangolo/fastapi/blob/aece74982d7c9c1acac98e2c872c4cb885677fc7/fastapi/security/http.py
raise HTTPException(403, detail='Missing bearer token') # must be 403 until solving https://github.com/tiangolo/fastapi/pull/2120