| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import abc |
| 4 |
import typing as t |
| 5 |
|
| 6 |
from ..response import OAuthAuthorizationCodeResponse |
| 7 |
|
| 8 |
|
| 9 |
class GlobusOAuthFlowManager(abc.ABC): |
| 10 |
""" |
| 11 |
An abstract class definition that defines the interface for the Flow |
| 12 |
Managers for Globus Auth. |
| 13 |
Flow Managers are really just bundles of parameters to Globus Auth's OAuth2 |
| 14 |
mechanisms, along with some useful utility methods. |
| 15 |
Primarily they can be used as a simple way of tracking small amounts of |
| 16 |
state in your application as it leverages Globus Auth for authentication. |
| 17 |
|
| 18 |
For sophisticated use cases, the provided Flow Managers will *NOT* be |
| 19 |
sufficient, but you should consider the provided objects a model. |
| 20 |
|
| 21 |
This way of managing OAuth2 flows is inspired by |
| 22 |
`oauth2client <https://github.com/google/oauth2client>`_. However, because |
| 23 |
``oauth2client`` has an uncertain future (as of 2016-08-31), and we would |
| 24 |
have to wrap it in order to provide a clean API surface anyway, we |
| 25 |
implement our own set of Flow objects. |
| 26 |
""" |
| 27 |
|
| 28 |
@abc.abstractmethod |
| 29 |
def get_authorize_url(self, query_params: dict[str, t.Any] | None = None) -> str: |
| 30 |
""" |
| 31 |
This method consumes no arguments or keyword arguments, and produces a |
| 32 |
string URL for the Authorize Step of a 3-legged OAuth2 flow. |
| 33 |
Most typically, this is the first step of the flow, and the user may be |
| 34 |
redirected to the URL or provided with a link. |
| 35 |
|
| 36 |
The authorize_url may be (usually is) parameterized over attributes of |
| 37 |
the specific flow manager instance which is generating it. |
| 38 |
|
| 39 |
:param query_params: Any additional parameters to be passed through |
| 40 |
as query params on the URL. |
| 41 |
""" |
| 42 |
|
| 43 |
@abc.abstractmethod |
| 44 |
def exchange_code_for_tokens( |
| 45 |
self, auth_code: str |
| 46 |
) -> OAuthAuthorizationCodeResponse: |
| 47 |
""" |
| 48 |
This method takes an auth_code and produces a response object |
| 49 |
containing one or more tokens. |
| 50 |
Most typically, this is the second step of the flow, and consumes the |
| 51 |
auth_code that was sent to a redirect URI used in the authorize step. |
| 52 |
|
| 53 |
The exchange process may be parameterized over attributes of the |
| 54 |
specific flow manager instance which is generating it. |
| 55 |
|
| 56 |
:param auth_code: The authorization code which was produced from the |
| 57 |
authorization flow |
| 58 |
""" |