Debian Codegraph @

src/globus_sdk/authorizers/base.py

raw
1 from __future__ import annotations
2
3 import abc
4
5
6 class GlobusAuthorizer(metaclass=abc.ABCMeta):
7 """
8 A ``GlobusAuthorizer`` is a very simple object which generates valid
9 Authorization headers.
10 It may also have handling for responses that indicate that it has provided
11 an invalid Authorization header.
12 """
13
14 @abc.abstractmethod
15 def get_authorization_header(self) -> str | None:
16 """
17 Get the value for the ``Authorization`` header from this authorizer.
18 If this method returns ``None``, then no ``Authorization`` header should be
19 used.
20 """
21
22 def handle_missing_authorization(self) -> bool:
23 """
24 This operation should be called if a request is made with an
25 Authorization header generated by this object which returns a 401
26 (HTTP Unauthorized).
27 If the ``GlobusAuthorizer`` thinks that it can take some action to
28 remedy this, it should update its state and return ``True``.
29 If the Authorizer cannot do anything in the event of a 401, this *may*
30 update state, but importantly returns ``False``.
31
32 By default, this always returns ``False`` and takes no other action.
33 """
34 return False
35
36
37 class StaticGlobusAuthorizer(GlobusAuthorizer):
38 """A static authorizer has some static string as its header val which it always
39 returns as the authz header."""
40
41 header_val: str
42
43 def get_authorization_header(self) -> str:
44 return self.header_val
45
46
47 class NullAuthorizer(GlobusAuthorizer):
48 """
49 This Authorizer implements No Authentication -- as in, it ensures that
50 there is no Authorization header.
51 """
52
53 def get_authorization_header(self) -> None:
54 return None