graphcore-kernel 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,7 @@ GRAPHCORE_TRUSTED_ISSUERS = [{
34
34
  'issuer': 'https://id.example.com/realms/notes', # public URL; matched against `iss`
35
35
  'audience': 'notes', # required in `aud`
36
36
  'internal_url': 'http://keycloak:8080/realms/notes', # optional: where this process fetches discovery and keys
37
+ 'web_client_id': 'notes-web', # optional: the public client the web frontend signs in as
37
38
  }]
38
39
  GRAPHCORE_PUBLIC_URL = 'https://notes.example.com' # optional: this deployment's origin behind a proxy
39
40
  ```
@@ -45,6 +46,9 @@ GRAPHCORE_PUBLIC_URL = 'https://notes.example.com' # optional: this deplo
45
46
  - `internal_url` changes only where discovery and the JWKS are fetched.
46
47
  `iss` is always matched against the public `issuer`, and a `jwks_uri`
47
48
  under the public URL is rewritten onto the internal one.
49
+ - `web_client_id` (default `graphcore-web`) and the first entry's `issuer`
50
+ are what `GET /graphcore/api/auth/client/` returns, unauthenticated. The
51
+ web frontend signs in with them, so its build names no issuer or client.
48
52
  - Nothing names a provider. Any issuer that publishes OIDC discovery and
49
53
  signs with RS256 works.
50
54
 
@@ -731,3 +731,37 @@ class TestAuthChallengeAndMe(TestCase):
731
731
  @override_settings(ROOT_URLCONF='graphcore.urls')
732
732
  def test_me_is_routed(self):
733
733
  self.assertEqual(resolve('/api/auth/me/').url_name, 'api_auth_me')
734
+
735
+
736
+ class TestAuthClientView(TestCase):
737
+ def setUp(self):
738
+ from graphcore.auth.authn.testing import TestIssuer
739
+
740
+ self.issuer = TestIssuer()
741
+
742
+ async def _get(self, entry: dict | None = None):
743
+ with self.issuer.trusted(entries=[{**self.issuer.settings_entry, **(entry or {})}]):
744
+ return await views.api_auth_client(RequestFactory().get('/'))
745
+
746
+ async def test_names_the_issuer_and_the_configured_web_client_without_a_token(self):
747
+ response = await self._get({'web_client_id': 'toast-web'})
748
+ self.assertEqual(response.status_code, 200)
749
+ self.assertEqual(json.loads(response.content), {'issuer': self.issuer.issuer, 'client_id': 'toast-web'})
750
+
751
+ async def test_defaults_to_graphcore_web(self):
752
+ response = await self._get()
753
+ self.assertEqual(json.loads(response.content)['client_id'], 'graphcore-web')
754
+
755
+ async def test_only_get(self):
756
+ with self.issuer.trusted():
757
+ response = await views.api_auth_client(RequestFactory().post('/'))
758
+ self.assertEqual(response.status_code, 405)
759
+
760
+ @override_settings(GRAPHCORE_TRUSTED_ISSUERS=[])
761
+ async def test_no_issuer_is_unavailable(self):
762
+ response = await views.api_auth_client(RequestFactory().get('/'))
763
+ self.assertEqual(response.status_code, 503)
764
+
765
+ @override_settings(ROOT_URLCONF='graphcore.urls')
766
+ def test_is_routed(self):
767
+ self.assertEqual(resolve('/api/auth/client/').url_name, 'api_auth_client')
@@ -23,6 +23,7 @@ urlpatterns = [
23
23
  path('api/execute_strategy_req/', views.api_execute_strategy_req, name='api_execute_strategy_req'),
24
24
 
25
25
  path('api/auth/me/', views.api_auth_me, name='api_auth_me'),
26
+ path('api/auth/client/', views.api_auth_client, name='api_auth_client'),
26
27
 
27
28
  path('api/invites/', views.api_create_invite, name='api_create_invite'),
28
29
  path('api/invites/redeem/', views.api_redeem_invite, name='api_redeem_invite'),
@@ -10,6 +10,7 @@ from graphcore.types.identity import Principal
10
10
  from graphcore.types.api import StrategyRequestPayload
11
11
  from graphcore.types.entities import EntityFilter, Tombstone, client_view
12
12
  from graphcore.auth.authn import authenticate, resource_metadata, strategy_tokens
13
+ from graphcore.auth.authn.authenticator import trusted_issuers
13
14
  from graphcore.api.predicate_codec import decode_predicate
14
15
  from graphcore.errors import (
15
16
  Forbidden, InvalidQuery, InvalidRequest, NotFound, UnsupportedQuery, log_and_correlate,
@@ -17,6 +18,8 @@ from graphcore.errors import (
17
18
 
18
19
  logger = logging.getLogger(__name__)
19
20
 
21
+ DEFAULT_WEB_CLIENT_ID = 'graphcore-web'
22
+
20
23
 
21
24
  def _error_response(logger_message: str, status: int = 500) -> JsonResponse:
22
25
  correlation_id = log_and_correlate(logger, logger_message)
@@ -73,6 +76,20 @@ async def api_auth_me(request):
73
76
  })
74
77
 
75
78
 
79
+ async def api_auth_client(request):
80
+ """Where the web frontend signs in, and as which public client: the
81
+ deployment's settings decide, so one frontend build works with any issuer."""
82
+ if request.method != 'GET':
83
+ return JsonResponse({'error': 'GET method required'}, status=405)
84
+ entry = next(iter(trusted_issuers().values()), None)
85
+ if entry is None:
86
+ return JsonResponse({'error': 'This deployment trusts no issuer'}, status=503)
87
+ return JsonResponse({
88
+ 'issuer': entry['issuer'],
89
+ 'client_id': entry.get('web_client_id') or DEFAULT_WEB_CLIENT_ID,
90
+ })
91
+
92
+
76
93
  async def api_get_entity_directory(request):
77
94
  if request.method != 'GET':
78
95
  return JsonResponse({'error': 'GET method required'}, status=400)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphcore-kernel
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: GraphCore platform kernel (entities, strategies, transport, auth)
5
5
  Author: GraphCore
6
6
  License-Expression: Apache-2.0
@@ -38,7 +38,7 @@ graphcore/api/tests/test_predicate_codec.py,sha256=0EFakHVkBfcynrTuRzEjQ722H0IHq
38
38
  graphcore/api/tests/test_strategy_tokens.py,sha256=ZkZDjUkUS0X6QETkxobCR_29EG7JrvChSBdjRDmQRwI,7180
39
39
  graphcore/api/tests/test_subtree_query.py,sha256=f2fH4tXuuRDJpTXSkFLA62k5LWJR0LcdL82gBNDHlNA,3172
40
40
  graphcore/auth/__init__.py,sha256=FC0n8yHDNVUw-PmOgq-e_YIhpDpobF1LOyW1NFDIfT0,56
41
- graphcore/auth/authn/README.md,sha256=eULtJZL35Ibk_Bi3Zw9fSAIj2T0GcdiyVbs-2ISbqr0,11999
41
+ graphcore/auth/authn/README.md,sha256=xBWgvREH95jKXYuFpW6MVuRrozcdEDvM1wk9Vk4HP-Y,12342
42
42
  graphcore/auth/authn/__init__.py,sha256=nKF01Qjq-qpO8GW1hMAEnv6-5QobRPY0M1FxT7-RE-Q,88
43
43
  graphcore/auth/authn/authenticator.py,sha256=rFcZElA4qiVKue8jLd4gT5aF9WYm5jlAmyKq1DC9fGg,4352
44
44
  graphcore/auth/authn/onboarding.py,sha256=lXMnDHm6nv1jHESmEr03PoCQO3DdaYHRnlmVXPgQVIQ,4811
@@ -315,11 +315,11 @@ graphcore/transport/agent_client.py,sha256=N95yQrYfIRR_uZhycGwRvdw6g8frSGRVN5qF9
315
315
  graphcore/transport/channel_layer.py,sha256=swLpod2gna5DMh6JZw3jWfNPJIaRVRKatdk7TnAyjgk,2871
316
316
  graphcore/transport/consumers.py,sha256=jLArPMKIUly148q5jY5hQSs4lpr1iB7D4R_l7nn0i9c,22321
317
317
  graphcore/transport/routing.py,sha256=mdC7l-5AVdKPV3t4j2O6y2XmgEK6YE9QPsMbK-D5kI4,176
318
- graphcore/transport/urls.py,sha256=Is7EcmiRn3JNLp_zqDsyM1yXHS0IHtVSPK7shjSq0cs,1483
319
- graphcore/transport/views.py,sha256=M7uK_H1ny6MY3vUJdqDoEdQ3cottApxWMzEpxx89vqs,14532
318
+ graphcore/transport/urls.py,sha256=r6ar0UhSlCk-06pv-r-iH2-v6zqdHULnDTYQxkQIt64,1560
319
+ graphcore/transport/views.py,sha256=ldVkOk5UQNXsEEOo5oo_-DrTf1T_bJYvnr2DZTa3Gec,15242
320
320
  graphcore/transport/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
321
321
  graphcore/transport/tests/test_agent_client.py,sha256=E4NG5B4X5nsLd75YiyJY7AE0ZQkY0I2UbEsyf0uZEew,1294
322
- graphcore/transport/tests/test_api_views.py,sha256=nngNEOTq4v3rRZcugAsj5AcxkITgnndftb5IRYzYWQM,34569
322
+ graphcore/transport/tests/test_api_views.py,sha256=52tsjw-e-MfY3LkSBXtauAvziJq2AXP2nxeGIYjjS4M,36044
323
323
  graphcore/transport/tests/test_channel_layer.py,sha256=fiyowHgNUj4cVuX0CXBD-crunF3xwcMdY8MTFDkxZC8,3639
324
324
  graphcore/transport/tests/test_consumers.py,sha256=BnASkNzQYNNlL71wO02hpYKK6vXaZb8a_gMWeV0zHe8,43564
325
325
  graphcore/transport/tests/test_resource_metadata.py,sha256=63JFpAC50PBMn9QOdJpuDtzDoKeqFtTscdEs1hsDnAk,3189
@@ -336,10 +336,10 @@ graphcore/types/schedules.py,sha256=4hMr6o0kJ6utbf-XSWFw_3_qkhpL3s32q6dsRdHmSIU,
336
336
  graphcore/types/strategy.py,sha256=De3z3aFC63s96SzDzNeCFXSS2L8yrmJV0ck2eEA6adw,2998
337
337
  graphcore/types/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
338
338
  graphcore/types/tests/test_entity_id.py,sha256=dvF0wLsN9aGRI0J11i__fSFC8bKQTO5Wj1oFu9-2T8Q,1885
339
- graphcore_kernel-0.2.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
340
- graphcore_kernel-0.2.1.dist-info/licenses/NOTICE,sha256=O2mV23MKwYlPOz9-8wsTSRNH3noH5-ie_sFFAvoOc_A,40
341
- graphcore_kernel-0.2.1.dist-info/METADATA,sha256=MKPRwqn1rqozeMZBWCJ1RbqGNVpLQ-wTKWAxCoJDbaE,3197
342
- graphcore_kernel-0.2.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
343
- graphcore_kernel-0.2.1.dist-info/entry_points.txt,sha256=PjyzUjOAsQAhWFDJvPh37PMh8lqypo_KUUDSK214j6Y,52
344
- graphcore_kernel-0.2.1.dist-info/top_level.txt,sha256=3GxRSE2Ws8H2BMLBStYy5hD2rMhuvDfOtoJ3EP-Pm3A,10
345
- graphcore_kernel-0.2.1.dist-info/RECORD,,
339
+ graphcore_kernel-0.2.2.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
340
+ graphcore_kernel-0.2.2.dist-info/licenses/NOTICE,sha256=O2mV23MKwYlPOz9-8wsTSRNH3noH5-ie_sFFAvoOc_A,40
341
+ graphcore_kernel-0.2.2.dist-info/METADATA,sha256=Dp-2k-AdGymM8uBNnDtw6nIMty0BN-5Jl0Vc2cl77RQ,3197
342
+ graphcore_kernel-0.2.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
343
+ graphcore_kernel-0.2.2.dist-info/entry_points.txt,sha256=PjyzUjOAsQAhWFDJvPh37PMh8lqypo_KUUDSK214j6Y,52
344
+ graphcore_kernel-0.2.2.dist-info/top_level.txt,sha256=3GxRSE2Ws8H2BMLBStYy5hD2rMhuvDfOtoJ3EP-Pm3A,10
345
+ graphcore_kernel-0.2.2.dist-info/RECORD,,