Skip to content

Commit deb0181

Browse files
committed
remove circular dependency between auth and key providers, use pubsub
1 parent eb3cbad commit deb0181

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

asab/web/auth/providers/id_token.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ def __init__(self, app, public_key_providers: typing.Iterable[PublicKeyProviderA
2929

3030
self.Authorizations = {}
3131

32+
self.App.PubSub.subscribe("PublicKey.updated!", self.collect_keys)
3233
self.App.PubSub.subscribe("Application.housekeeping!", self._delete_invalid_authorizations)
3334
self.App.TaskService.schedule(self._update_public_keys())
3435

3536

3637
def register_key_provider(self, provider: PublicKeyProviderABC):
37-
if self not in provider.AuthProviders:
38-
provider.AuthProviders.add(self)
3938
self._KeyProviders.add(provider)
4039
self.collect_keys()
4140

@@ -54,7 +53,7 @@ async def authorize(self, request: aiohttp.web.Request) -> Authorization:
5453
return authz
5554

5655

57-
def collect_keys(self):
56+
def collect_keys(self, *args, **kwargs):
5857
"""
5958
Collect public keys from all key providers into a single trusted JWK set.
6059
"""

asab/web/auth/providers/key_providers/abc.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class PublicKeyProviderABC(abc.ABC):
1515

1616
def __init__(self, app):
1717
self.App = app
18-
self.AuthProviders = set() # Auth providers that use this public key provider
1918
self.TaskService = self.App.get_service("asab.TaskService")
2019
self.PublicKeySet: jwcrypto.jwk.JWKSet = jwcrypto.jwk.JWKSet()
2120

@@ -42,5 +41,4 @@ def _set_keys(self, keys: typing.Optional[typing.Union[jwcrypto.jwk.JWK, jwcrypt
4241
else:
4342
raise ValueError("Invalid public_key type.")
4443

45-
for auth_provider in self.AuthProviders:
46-
auth_provider.collect_keys()
44+
self.App.PubSub.publish("PublicKey.updated!", self)

0 commit comments

Comments
 (0)