Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consent forest sc 30764 #971

Merged
merged 11 commits into from
Apr 19, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Added
~~~~~

- Added a new AuthClient method ``get_consents`` and supporting local data objects.
These allows a client to poll and interact with the current Globus Auth consent state
of a particular identity rooted at their client. (:pr:`NUMBER`)
20 changes: 20 additions & 0 deletions docs/services/auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ batching, and other functionality.
:exclude-members: __dict__,__weakref__
:show-inheritance:

.. autoclass:: ConsentForest
:members:

.. autoclass:: ConsentTree
:members:

.. autoclass:: Consent
:members:

.. autoclass:: DependentScopeSpec

Auth Responses
Expand All @@ -65,10 +74,21 @@ Auth Responses
:members:
:show-inheritance:

.. autoclass:: GetConsentsResponse
:members:
:show-inheritance:

.. autoclass:: GetIdentitiesResponse
:members:
:show-inheritance:

Errors
------

.. autoexception:: AuthAPIError

.. autoexception:: ConsentParseError

OAuth2 Flow Managers
--------------------

Expand Down
15 changes: 15 additions & 0 deletions src/globus_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def _force_eager_imports() -> None:
"NativeAppAuthClient",
"ConfidentialAppAuthClient",
"AuthAPIError",
"ConsentParseError",
"Consent",
"ConsentTree",
"ConsentForest",
"IdentityMap",
"GetConsentsResponse",
"GetIdentitiesResponse",
"OAuthDependentTokenResponse",
"OAuthTokenResponse",
Expand Down Expand Up @@ -171,7 +176,12 @@ def _force_eager_imports() -> None:
from .services.auth import NativeAppAuthClient
from .services.auth import ConfidentialAppAuthClient
from .services.auth import AuthAPIError
from .services.auth import ConsentParseError
from .services.auth import Consent
from .services.auth import ConsentTree
from .services.auth import ConsentForest
from .services.auth import IdentityMap
from .services.auth import GetConsentsResponse
from .services.auth import GetIdentitiesResponse
from .services.auth import OAuthDependentTokenResponse
from .services.auth import OAuthTokenResponse
Expand Down Expand Up @@ -289,6 +299,10 @@ def __getattr__(name: str) -> t.Any:
"CollectionDocument",
"CollectionPolicies",
"ConfidentialAppAuthClient",
"Consent",
"ConsentForest",
"ConsentParseError",
"ConsentTree",
"DeleteData",
"DependentScopeSpec",
"EndpointDocument",
Expand All @@ -298,6 +312,7 @@ def __getattr__(name: str) -> t.Any:
"GCSAPIError",
"GCSClient",
"GCSRoleDocument",
"GetConsentsResponse",
"GetIdentitiesResponse",
"GlobusAPIError",
"GlobusConnectPersonalOwnerInfo",
Expand Down
5 changes: 5 additions & 0 deletions src/globus_sdk/_generate_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ def __getattr__(name: str) -> t.Any:
"ConfidentialAppAuthClient",
# errors
"AuthAPIError",
"ConsentParseError",
# high-level helpers
"Consent",
"ConsentTree",
"ConsentForest",
"IdentityMap",
# responses
"GetConsentsResponse",
"GetIdentitiesResponse",
"OAuthDependentTokenResponse",
"OAuthTokenResponse",
Expand Down
49 changes: 49 additions & 0 deletions src/globus_sdk/_testing/data/auth/get_consents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from globus_sdk._testing.models import RegisteredResponse, ResponseSet

_DATA_ACCESS = (
"https://auth.globus.org/scopes/542a86fc-1766-450d-841f-065488a2ec01/data_access"
)

RESPONSES = ResponseSet(
default=RegisteredResponse(
service="auth",
path="/v2/api/identities/8ca28797-3541-4a5d-a264-05b00f91e608/consents",
json={
"consents": [
{
"created": "2022-09-21T17:10:14.270581+00:00",
"id": 142632,
"status": "approved",
"updated": "2022-09-21T17:10:14.270581+00:00",
"allows_refresh": True,
"dependency_path": [142632],
"scope_name": "urn:globus:auth:scope:transfer.api.globus.org:all",
"atomically_revocable": False,
"effective_identity": "8ca28797-3541-4a5d-a264-05b00f91e608",
"auto_approved": False,
"last_used": "2024-03-18T17:34:04.719126+00:00",
"scope": "89ecabba-4acf-4e2e-a98d-ce592ccc2818",
"client": "065db752-2f43-4fe1-a633-2ee68c9da889",
},
{
"created": "2024-03-18T17:32:51.496893+00:00",
"id": 433892,
"status": "approved",
"updated": "2024-03-18T17:32:51.496893+00:00",
"allows_refresh": True,
"dependency_path": [142632, 433892],
"scope_name": _DATA_ACCESS,
"atomically_revocable": True,
"effective_identity": "8ca28797-3541-4a5d-a264-05b00f91e608",
"auto_approved": False,
"last_used": "2024-03-18T17:33:05.178254+00:00",
"scope": "fe334c19-4fe6-4d03-ac73-8992beb231b6",
"client": "2fbdda78-a599-4cb5-ac3d-1fbcfbc6a754",
},
]
},
metadata={
"identity_id": "8ca28797-3541-4a5d-a264-05b00f91e608",
},
),
)
1 change: 1 addition & 0 deletions src/globus_sdk/scopes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class _AuthScopesBuilder(ScopeBuilder):
"view_authentications",
"view_clients",
"view_clients_and_scopes",
"view_consents",
"view_identities",
"view_identity_set",
],
Expand Down
11 changes: 9 additions & 2 deletions src/globus_sdk/services/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
ConfidentialAppAuthClient,
NativeAppAuthClient,
)
from .consents import Consent, ConsentForest, ConsentTree
from .data import DependentScopeSpec
from .errors import AuthAPIError
from .errors import AuthAPIError, ConsentParseError
from .flow_managers import (
GlobusAuthorizationCodeFlowManager,
GlobusNativeAppFlowManager,
)
from .identity_map import IdentityMap
from .response import (
GetConsentsResponse,
GetIdentitiesResponse,
OAuthDependentTokenResponse,
OAuthTokenResponse,
Expand All @@ -25,13 +27,18 @@
"ConfidentialAppAuthClient",
# errors
"AuthAPIError",
"ConsentParseError",
# high-level helpers
"IdentityMap",
"Consent",
"ConsentTree",
"ConsentForest",
"DependentScopeSpec",
"IdentityMap",
# flow managers
"GlobusNativeAppFlowManager",
"GlobusAuthorizationCodeFlowManager",
# responses
"GetConsentsResponse",
"GetIdentitiesResponse",
"OAuthDependentTokenResponse",
"OAuthTokenResponse",
Expand Down
31 changes: 30 additions & 1 deletion src/globus_sdk/services/auth/client/service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..response import (
GetClientCredentialsResponse,
GetClientsResponse,
GetConsentsResponse,
GetIdentitiesResponse,
GetIdentityProvidersResponse,
GetPoliciesResponse,
Expand Down Expand Up @@ -1789,7 +1790,7 @@ def delete_scope(self, scope_id: UUIDLike) -> GlobusHTTPResponse:

>>> ac = globus_sdk.AuthClient(...)
>>> scope_id = ...
>>> r = ac.delete_policy(scope_id)
>>> r = ac.delete_scope(scope_id)

.. tab-item:: Example Response Data

Expand All @@ -1803,3 +1804,31 @@ def delete_scope(self, scope_id: UUIDLike) -> GlobusHTTPResponse:
:ref: auth/reference/#delete_scope
"""
return self.delete(f"/v2/api/scopes/{scope_id}")

def get_consents(self, identity_id: UUIDLike) -> GetConsentsResponse:
"""
Look up consents for a user. Requires the ``view_consents`` scope.
joshbryan-globus marked this conversation as resolved.
Show resolved Hide resolved

:param identity_id: The ID of the identity to look up consents for

.. tab-set::

.. tab-item:: Example Usage

.. code-block:: pycon

>>> ac = globus_sdk.AuthClient(...)
>>> identity_id = ...
>>> forest = ac.get_consents(identity_id).to_forest()

.. tab-item:: Example Response Data

.. expandtestfixture:: auth.get_consents

.. tab-item:: API Info

``GET /v2/api/identities/{identity_id}/consents``
"""
return GetConsentsResponse(
self.get(f"/v2/api/identities/{identity_id}/consents"),
)
Loading