Created
April 15, 2019 11:33
-
-
Save nilsdebruin/bb0b8e5924adef7fc7082cd26b1bb65f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BasicAuth(SecurityBase): | |
| def __init__(self, scheme_name: str = None, auto_error: bool = True): | |
| self.scheme_name = scheme_name or self.__class__.__name__ | |
| self.auto_error = auto_error | |
| async def __call__(self, request: Request) -> Optional[str]: | |
| authorization: str = request.headers.get("Authorization") | |
| scheme, param = get_authorization_scheme_param(authorization) | |
| if not authorization or scheme.lower() != "basic": | |
| if self.auto_error: | |
| raise HTTPException( | |
| status_code=HTTP_403_FORBIDDEN, detail="Not authenticated" | |
| ) | |
| else: | |
| return None | |
| return param | |
| basic_auth = BasicAuth(auto_error=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment