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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
.. _scope_collections:
.. currentmodule:: globus_sdk.scopes
ScopeCollections
================
OAuth2 Scopes for various Globus services are represented by ``ScopeCollection``
objects.
These are containers for constant :class:`Scope` objects.
Scope collections are provided directly via ``globus_sdk.scopes`` and are also
accessible via the relevant client classes.
Direct Use
----------
To use the scope collections directly, import from ``globus_sdk.scopes``.
For example, one might use the Transfer "all" scope during a login flow like
so:
.. code-block:: python
import globus_sdk
from globus_sdk.scopes import TransferScopes
CLIENT_ID = "<YOUR_ID_HERE>"
client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
client.oauth2_start_flow(requested_scopes=[TransferScopes.all])
...
As Client Attributes
--------------------
Token scopes are associated with a particular client which will use that token.
Because of this, each service client contains a ``ScopeCollection`` attribute
(``client.scopes``) defining the relevant scopes for that client.
For most client classes, this is a class attribute. For example, accessing
``TransferClient.scopes`` is valid:
.. code-block:: python
import globus_sdk
CLIENT_ID = "<YOUR_ID_HERE>"
client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
client.oauth2_start_flow(requested_scopes=[globus_sdk.TransferClient.scopes.all])
...
# or, potentially, after there is a concrete client
tc = globus_sdk.TransferClient()
client.oauth2_start_flow(requested_scopes=[tc.scopes.all])
As Instance Attributes and Methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some client classes only provide their scopes for instances. These cases cover
services which are distributed or contain multiple subservices with their own
scopes.
For example, ``GCSClient`` and ``SpecificFlowClient`` each have a ``scopes``
attribute of ``None`` on their classes.
In the case of ``SpecificFlowClient``, scopes are populated whenever an
instance is instantiated. So the following usage is valid:
.. code-block:: python
import globus_sdk
FLOW_ID = "<YOUR_ID_HERE>"
client = globus_sdk.SpecificFlowClient(FLOW_ID)
flow_user_scope = client.scopes.user
In the case of GCS, a distributed service, ``scopes`` is always ``None``.
However, :meth:`globus_sdk.GCSClient.get_gcs_endpoint_scopes` and
:meth:`globus_sdk.GCSClient.get_gcs_collection_scopes` are available helpers
for getting specific collections of scopes.
Using a Scope Collection to Get Matching Tokens
-----------------------------------------------
A ``ScopeCollection`` contains the resource server name used to get token data
from a token response.
To elaborate on the above example:
.. code-block:: python
import globus_sdk
from globus_sdk.scopes import TransferScopes
CLIENT_ID = "<YOUR_ID_HERE>"
client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
client.oauth2_start_flow(requested_scopes=[TransferScopes.all])
authorize_url = client.oauth2_get_authorize_url()
print("Please go to this URL and login:", authorize_url)
auth_code = input("Please enter the code you get after login here: ").strip()
token_response = client.oauth2_exchange_code_for_tokens(auth_code)
# use the `resource_server` of a ScopeBuilder to grab the associated token
# data from the response
tokendata = token_response.by_resource_server[TransferScopes.resource_server]
Reference
---------
Collection Types
~~~~~~~~~~~~~~~~
.. autoclass:: ScopeCollection
:members:
:show-inheritance:
.. autoclass:: StaticScopeCollection
:members:
:show-inheritance:
.. autoclass:: DynamicScopeCollection
:members:
:show-inheritance:
.. autoclass:: GCSEndpointScopes
:members:
:show-inheritance:
.. autoclass:: GCSCollectionScopes
:members:
:show-inheritance:
.. autoclass:: SpecificFlowScopes
:members:
:show-inheritance:
Collection Constants
~~~~~~~~~~~~~~~~~~~~
.. py:data:: globus_sdk.scopes.data.AuthScopes
Globus Auth scopes.
.. listknownscopes:: globus_sdk.scopes.AuthScopes
:example_scope: view_identity_set
.. py:data:: globus_sdk.scopes.data.ComputeScopes
Compute scopes.
.. listknownscopes:: globus_sdk.scopes.ComputeScopes
.. py:data:: globus_sdk.scopes.data.FlowsScopes
Globus Flows scopes.
.. listknownscopes:: globus_sdk.scopes.FlowsScopes
.. py:data:: globus_sdk.scopes.data.GroupsScopes
Groups scopes.
.. listknownscopes:: globus_sdk.scopes.GroupsScopes
.. py:data:: globus_sdk.scopes.data.NexusScopes
Nexus scopes.
.. listknownscopes:: globus_sdk.scopes.NexusScopes
.. warning::
Use of Nexus is deprecated. Users should use Groups instead.
.. py:data:: globus_sdk.scopes.data.SearchScopes
Globus Search scopes.
.. listknownscopes:: globus_sdk.scopes.SearchScopes
.. py:data:: globus_sdk.scopes.data.TimersScopes
Globus Timers scopes.
.. listknownscopes:: globus_sdk.scopes.TimersScopes
.. py:data:: globus_sdk.scopes.data.TransferScopes
Globus Transfer scopes.
.. listknownscopes:: globus_sdk.scopes.TransferScopes
|