-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Move login flows (#1057)
* Promote login flow managers from 'experimental' * Add LoginFlowManagers to docs * Fix import path * Cosmetic changes * Only allow native apps to use localserver login flow manager * Fix raises class references
1 parent
4afc1f9
commit f1f450c
Showing
24 changed files
with
330 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
Changed | ||
~~~~~~~ | ||
|
||
- LoginFlowManagers have been moved from ``globus_sdk.experimental.login_flow_managers`` | ||
to ``globus_sdk.login_flows``. (:pr:`NUMBER`) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
|
||
Login Flow Managers | ||
=================== | ||
|
||
.. currentmodule:: globus_sdk.login_flows | ||
|
||
This page provides references for the LoginFlowManager abstract class and some concrete | ||
implementations. | ||
|
||
A login flow manager is a class responsible for driving a user through a login flow, | ||
with the ultimate goal of obtaining tokens. The tokens are required to make | ||
requests against any Globus services. | ||
|
||
Interface | ||
--------- | ||
|
||
.. autoclass:: LoginFlowManager | ||
:members: | ||
|
||
Command Line | ||
------------ | ||
|
||
As the name might suggest, a CommandLineLoginFlowManager drives user logins through | ||
the command line (stdin/stdout). When run, the manager will print a URL to the console | ||
then prompt a user to navigate to that URL and enter the resulting auth code | ||
back into the terminal. | ||
|
||
Example Code: | ||
|
||
.. code-block:: pycon | ||
>>> from globus_sdk import NativeAppAuthClient | ||
>>> from globus_sdk.scopes import TransferScopes | ||
>>> from globus_sdk.login_flows import CommandLineLoginFlowManager | ||
>>> login_client = NativeAppAuthClient(client_id=client_id) | ||
>>> manager = CommandLineLoginFlowManager(login_client) | ||
>>> | ||
>>> token_response = manager.run_login_flow( | ||
... GlobusAuthorizationParameters(required_scopes=[TransferScopes.all]) | ||
... ) | ||
Please authenticate with Globus here: | ||
------------------------------------- | ||
https://auth.globus.org/v2/oauth2/authorize?cli...truncated... | ||
------------------------------------- | ||
Enter the resulting Authorization Code here: | ||
.. autoclass:: CommandLineLoginFlowManager | ||
:members: | ||
:member-order: bysource | ||
:show-inheritance: | ||
|
||
Local Server | ||
------------ | ||
|
||
A LocalServerLoginFlowManager drives more automated, but less portable, login flows | ||
compared with its command line counterpart. When run, rather than printing the | ||
authorization URL, the manager will open it in the user's default browser. Alongside | ||
this, the manager will start a local web server to receive the auth code upon completion | ||
of the login flow. | ||
|
||
This provides a more user-friendly login experience as there is no manually copy/pasting | ||
of links and codes. It also requires however that the python process be running in an | ||
environment with access to a supported browser. As such, this flow is not suitable for | ||
headless environments (e.g., while ssh-ed into a cluster node). | ||
|
||
.. note:: | ||
|
||
This login manager is only supported for native clients. | ||
|
||
|
||
Example Usage: | ||
|
||
.. code-block:: pycon | ||
>>> from globus_sdk import NativeAppAuthClient | ||
>>> from globus_sdk.scopes import TransferScopes | ||
>>> from globus_sdk.login_flows import LocalServerLoginFlowManager | ||
>>> login_client = NativeAppAuthClient(client_id=client_id) | ||
>>> manager = LocalServerLoginFlowManager(login_client) | ||
>>> | ||
>>> token_response = manager.run_login_flow( | ||
... GlobusAuthorizationParameters(required_scopes=[TransferScopes.all]) | ||
... ) | ||
.. autoclass:: LocalServerLoginFlowManager | ||
:members: | ||
:member-order: bysource | ||
:show-inheritance: | ||
|
||
.. autoexception:: LocalServerLoginError | ||
|
||
.. autoexception:: LocalServerEnvironmentalLoginError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
import typing as t | ||
|
||
__all__ = ( | ||
"CommandLineLoginFlowManager", | ||
"LocalServerLoginFlowManager", | ||
"LoginFlowManager", | ||
) | ||
|
||
# legacy aliases | ||
# (when accessed, these will emit deprecation warnings) | ||
if t.TYPE_CHECKING: | ||
from globus_sdk.login_flows import ( | ||
CommandLineLoginFlowManager, | ||
LocalServerLoginFlowManager, | ||
LoginFlowManager, | ||
) | ||
else: | ||
|
||
def __getattr__(name: str) -> t.Any: | ||
import globus_sdk.login_flows as login_flows_module | ||
from globus_sdk.exc import warn_deprecated | ||
|
||
warn_deprecated( | ||
"'globus_sdk.experimental.login_flow_manager' has been renamed to " | ||
"'globus_sdk.login_flows'. " | ||
f"Importing '{name}' from `globus_sdk.experimental` is deprecated. " | ||
f"Use `globus_sdk.login_flows.{name}` instead." | ||
) | ||
|
||
value = getattr(login_flows_module, name, None) | ||
if value is None: | ||
raise AttributeError(f"module {__name__} has no attribute {name}") | ||
setattr(sys.modules[__name__], name, value) | ||
return value |
5 changes: 0 additions & 5 deletions
5
src/globus_sdk/experimental/login_flow_manager/local_server_login_flow_manager/__init__.py
This file was deleted.
Oops, something went wrong.
10 changes: 8 additions & 2 deletions
10
...perimental/login_flow_manager/__init__.py → src/globus_sdk/login_flows/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from .command_line_login_flow_manager import CommandLineLoginFlowManager | ||
from .local_server_login_flow_manager import LocalServerLoginFlowManager | ||
from .local_server_login_flow_manager import ( | ||
LocalServerEnvironmentalLoginError, | ||
LocalServerLoginError, | ||
LocalServerLoginFlowManager, | ||
) | ||
from .login_flow_manager import LoginFlowManager | ||
|
||
__all__ = [ | ||
"LoginFlowManager", | ||
"CommandLineLoginFlowManager", | ||
"LocalServerLoginError", | ||
"LocalServerEnvironmentalLoginError", | ||
"LocalServerLoginFlowManager", | ||
"LoginFlowManager", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/globus_sdk/login_flows/local_server_login_flow_manager/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .errors import LocalServerEnvironmentalLoginError, LocalServerLoginError | ||
from .local_server_login_flow_manager import LocalServerLoginFlowManager | ||
|
||
__all__ = [ | ||
"LocalServerLoginError", | ||
"LocalServerEnvironmentalLoginError", | ||
"LocalServerLoginFlowManager", | ||
] |
9 changes: 9 additions & 0 deletions
9
src/globus_sdk/login_flows/local_server_login_flow_manager/errors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class LocalServerLoginError(Exception): | ||
"""An error raised during a LocalServerLoginFlowManager's run.""" | ||
|
||
|
||
class LocalServerEnvironmentalLoginError(LocalServerLoginError): | ||
""" | ||
Error raised when a local server login flow fails to start due to incompatible | ||
environment conditions (e.g., a remote session or text-only browser). | ||
""" |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters