File: login_flows.rst

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (99 lines) | stat: -rw-r--r-- 3,148 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.. _login_flow_managers:

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:


.. autoexception:: CommandLineLoginFlowEOFError

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