Debian Codegraph @

docs/authorization/scopes_and_consents/scope_collections.rst

raw
1 .. _scope_collections:
2
3 .. currentmodule:: globus_sdk.scopes
4
5 ScopeCollections
6 ================
7
8 OAuth2 Scopes for various Globus services are represented by ``ScopeCollection``
9 objects.
10 These are containers for constant :class:`Scope` objects.
11
12 Scope collections are provided directly via ``globus_sdk.scopes`` and are also
13 accessible via the relevant client classes.
14
15 Direct Use
16 ----------
17
18 To use the scope collections directly, import from ``globus_sdk.scopes``.
19
20 For example, one might use the Transfer "all" scope during a login flow like
21 so:
22
23 .. code-block:: python
24
25 import globus_sdk
26 from globus_sdk.scopes import TransferScopes
27
28 CLIENT_ID = "<YOUR_ID_HERE>"
29
30 client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
31 client.oauth2_start_flow(requested_scopes=[TransferScopes.all])
32 ...
33
34 As Client Attributes
35 --------------------
36
37 Token scopes are associated with a particular client which will use that token.
38 Because of this, each service client contains a ``ScopeCollection`` attribute
39 (``client.scopes``) defining the relevant scopes for that client.
40
41 For most client classes, this is a class attribute. For example, accessing
42 ``TransferClient.scopes`` is valid:
43
44 .. code-block:: python
45
46 import globus_sdk
47
48 CLIENT_ID = "<YOUR_ID_HERE>"
49
50 client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
51 client.oauth2_start_flow(requested_scopes=[globus_sdk.TransferClient.scopes.all])
52 ...
53
54 # or, potentially, after there is a concrete client
55 tc = globus_sdk.TransferClient()
56 client.oauth2_start_flow(requested_scopes=[tc.scopes.all])
57
58 As Instance Attributes and Methods
59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
61 Some client classes only provide their scopes for instances. These cases cover
62 services which are distributed or contain multiple subservices with their own
63 scopes.
64
65 For example, ``GCSClient`` and ``SpecificFlowClient`` each have a ``scopes``
66 attribute of ``None`` on their classes.
67
68 In the case of ``SpecificFlowClient``, scopes are populated whenever an
69 instance is instantiated. So the following usage is valid:
70
71 .. code-block:: python
72
73 import globus_sdk
74
75 FLOW_ID = "<YOUR_ID_HERE>"
76
77 client = globus_sdk.SpecificFlowClient(FLOW_ID)
78 flow_user_scope = client.scopes.user
79
80 In the case of GCS, a distributed service, ``scopes`` is always ``None``.
81 However, :meth:`globus_sdk.GCSClient.get_gcs_endpoint_scopes` and
82 :meth:`globus_sdk.GCSClient.get_gcs_collection_scopes` are available helpers
83 for getting specific collections of scopes.
84
85 Using a Scope Collection to Get Matching Tokens
86 -----------------------------------------------
87
88 A ``ScopeCollection`` contains the resource server name used to get token data
89 from a token response.
90 To elaborate on the above example:
91
92 .. code-block:: python
93
94 import globus_sdk
95 from globus_sdk.scopes import TransferScopes
96
97 CLIENT_ID = "<YOUR_ID_HERE>"
98
99 client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
100 client.oauth2_start_flow(requested_scopes=[TransferScopes.all])
101 authorize_url = client.oauth2_get_authorize_url()
102 print("Please go to this URL and login:", authorize_url)
103 auth_code = input("Please enter the code you get after login here: ").strip()
104 token_response = client.oauth2_exchange_code_for_tokens(auth_code)
105
106 # use the `resource_server` of a ScopeBuilder to grab the associated token
107 # data from the response
108 tokendata = token_response.by_resource_server[TransferScopes.resource_server]
109
110
111 Reference
112 ---------
113
114 Collection Types
115 ~~~~~~~~~~~~~~~~
116
117 .. autoclass:: ScopeCollection
118 :members:
119 :show-inheritance:
120
121 .. autoclass:: StaticScopeCollection
122 :members:
123 :show-inheritance:
124
125 .. autoclass:: DynamicScopeCollection
126 :members:
127 :show-inheritance:
128
129 .. autoclass:: GCSEndpointScopes
130 :members:
131 :show-inheritance:
132
133 .. autoclass:: GCSCollectionScopes
134 :members:
135 :show-inheritance:
136
137 .. autoclass:: SpecificFlowScopes
138 :members:
139 :show-inheritance:
140
141 Collection Constants
142 ~~~~~~~~~~~~~~~~~~~~
143
144 .. py:data:: globus_sdk.scopes.data.AuthScopes
145
146 Globus Auth scopes.
147
148 .. listknownscopes:: globus_sdk.scopes.AuthScopes
149 :example_scope: view_identity_set
150
151
152 .. py:data:: globus_sdk.scopes.data.ComputeScopes
153
154 Compute scopes.
155
156 .. listknownscopes:: globus_sdk.scopes.ComputeScopes
157
158
159 .. py:data:: globus_sdk.scopes.data.FlowsScopes
160
161 Globus Flows scopes.
162
163 .. listknownscopes:: globus_sdk.scopes.FlowsScopes
164
165
166 .. py:data:: globus_sdk.scopes.data.GroupsScopes
167
168 Groups scopes.
169
170 .. listknownscopes:: globus_sdk.scopes.GroupsScopes
171
172
173 .. py:data:: globus_sdk.scopes.data.NexusScopes
174
175 Nexus scopes.
176
177 .. listknownscopes:: globus_sdk.scopes.NexusScopes
178
179 .. warning::
180
181 Use of Nexus is deprecated. Users should use Groups instead.
182
183
184 .. py:data:: globus_sdk.scopes.data.SearchScopes
185
186 Globus Search scopes.
187
188 .. listknownscopes:: globus_sdk.scopes.SearchScopes
189
190
191 .. py:data:: globus_sdk.scopes.data.TimersScopes
192
193 Globus Timers scopes.
194
195 .. listknownscopes:: globus_sdk.scopes.TimersScopes
196
197
198 .. py:data:: globus_sdk.scopes.data.TransferScopes
199
200 Globus Transfer scopes.
201
202 .. listknownscopes:: globus_sdk.scopes.TransferScopes