Debian Codegraph @

src/globus_sdk/authorizers/basic.py

raw
1 import base64
2 import logging
3
4 from .base import StaticGlobusAuthorizer
5
6 log = logging.getLogger(__name__)
7
8
9 class BasicAuthorizer(StaticGlobusAuthorizer):
10 """
11 This Authorizer implements Basic Authentication.
12 Given a "username" and "password", they are sent base64 encoded in the
13 header.
14
15 :param username: Username component for Basic Auth
16 :param password: Password component for Basic Auth
17 """
18
19 def __init__(self, username: str, password: str) -> None:
20 log.debug(
21 "Setting up a BasicAuthorizer. It will use an "
22 "auth type of Basic and cannot handle 401s."
23 )
24 log.debug(f"BasicAuthorizer.username = {username}")
25 self.username = username
26 self.password = password
27
28 to_b64 = f"{username}:{password}"
29 self.header_val = f"Basic {_b64str(to_b64)}"
30
31
32 def _b64str(s: str) -> str:
33 return base64.b64encode(s.encode("utf-8")).decode("utf-8")