| 1 |
import logging |
| 2 |
|
| 3 |
from globus_sdk._internal.utils import sha256_string |
| 4 |
|
| 5 |
from .base import StaticGlobusAuthorizer |
| 6 |
|
| 7 |
log = logging.getLogger(__name__) |
| 8 |
|
| 9 |
|
| 10 |
class AccessTokenAuthorizer(StaticGlobusAuthorizer): |
| 11 |
""" |
| 12 |
Implements Authorization using a single Access Token with no Refresh |
| 13 |
Tokens. This is sent as a Bearer token in the header -- basically |
| 14 |
unadorned. |
| 15 |
|
| 16 |
:param access_token: An access token for Globus Auth |
| 17 |
""" |
| 18 |
|
| 19 |
def __init__(self, access_token: str) -> None: |
| 20 |
log.debug( |
| 21 |
"Setting up an AccessTokenAuthorizer. It will use an " |
| 22 |
"auth type of Bearer and cannot handle 401s." |
| 23 |
) |
| 24 |
self.access_token = access_token |
| 25 |
self.header_val = "Bearer %s" % access_token |
| 26 |
|
| 27 |
self.access_token_hash = sha256_string(self.access_token) |
| 28 |
log.debug(f'Bearer token has hash "{self.access_token_hash}"') |