Allows the 'auth' argument to be passed as a (username, password) pair, and uses HTTP Basic authentication.
| 124 | |
| 125 | |
| 126 | class BasicAuth(Auth): |
| 127 | """ |
| 128 | Allows the 'auth' argument to be passed as a (username, password) pair, |
| 129 | and uses HTTP Basic authentication. |
| 130 | """ |
| 131 | |
| 132 | def __init__(self, username: str | bytes, password: str | bytes) -> None: |
| 133 | self._auth_header = self._build_auth_header(username, password) |
| 134 | |
| 135 | def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]: |
| 136 | request.headers["Authorization"] = self._auth_header |
| 137 | yield request |
| 138 | |
| 139 | def _build_auth_header(self, username: str | bytes, password: str | bytes) -> str: |
| 140 | userpass = b":".join((to_bytes(username), to_bytes(password))) |
| 141 | token = b64encode(userpass).decode() |
| 142 | return f"Basic {token}" |
| 143 | |
| 144 | |
| 145 | class NetRCAuth(Auth): |
no outgoing calls
no test coverage detected