Skip to content

Commit 3b8be90

Browse files
nicornkclaude
andauthored
Feat/scope api (#119)
* feat: add api_me_scope to MultipassClient for me/scope endpoint Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: document api_me_scope response structure and add type assertion to test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style: use plain requests.Response in docstring for consistency Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 48d4679 commit 3b8be90

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

libs/foundry-dev-tools/src/foundry_dev_tools/clients/multipass.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,53 @@ def api_me(self, **kwargs) -> requests.Response:
9595
**kwargs,
9696
)
9797

98+
def api_me_scope(self, **kwargs) -> requests.Response:
99+
"""Gets the current user's scope.
100+
101+
Args:
102+
**kwargs: gets passed to :py:meth:`APIClient.api_request`
103+
104+
Returns:
105+
requests.Response:
106+
The response JSON is a recursive scope structure with a ``type`` field.
107+
108+
.. code-block:: python
109+
110+
# User token:
111+
{"type": "universal"}
112+
113+
# Scoped token (e.g. TPA with authorization_code grant):
114+
{
115+
"type": "union",
116+
"scopes": [
117+
{
118+
"type": "intersection",
119+
"scopes": [
120+
{"type": "operation", "operations": ["api:read-data", ...]},
121+
{"type": "operation", "operations": ["api:read-data", ...]},
122+
],
123+
},
124+
{
125+
"type": "intersection",
126+
"scopes": [
127+
{
128+
"type": "resource",
129+
"resourceIds": ["ri.multipass..organization.root"],
130+
"includeChildren": True,
131+
},
132+
{"type": "operation", "operations": ["organization:discover", ...]},
133+
],
134+
},
135+
],
136+
}
137+
138+
"""
139+
return self.api_request(
140+
"GET",
141+
"me/scope",
142+
**kwargs,
143+
)
144+
98145
def search(
99146
self, query: str, principal_types: set[api_types.PrincipalTypes] | None = None, **kwargs
100147
) -> Iterator[dict]:

tests/integration/clients/test_multipass.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def _tear_down():
4545
raise
4646

4747

48+
def test_me_scope():
49+
resp = TEST_SINGLETON.ctx.multipass.api_me_scope()
50+
51+
assert resp.status_code == 200
52+
53+
scope = resp.json()
54+
assert isinstance(scope, dict)
55+
assert "type" in scope
56+
assert scope["type"] in ("universal", "union", "intersection", "operation", "resource")
57+
58+
4859
def test_organizations():
4960
user_info = TEST_SINGLETON.ctx.multipass.get_user_info()
5061

0 commit comments

Comments
 (0)