Skip to content

Commit eb3cbad

Browse files
committed
introduce auth mode=development
1 parent 6dbb25c commit eb3cbad

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

asab/web/auth/providers/id_token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def initialize(self):
4646

4747
async def authorize(self, request: aiohttp.web.Request) -> Authorization:
4848
if not self._KeyProviders:
49-
L.debug("No public key providers registered for ID token authentication.")
49+
L.warning("No public key providers registered for ID token authentication.")
5050
raise NotAuthenticatedError()
5151

5252
bearer_token = get_bearer_token_from_authorization_header(request)

asab/web/auth/service.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,28 @@ def _set_up_providers(self):
156156
from .providers.key_providers import UrlPublicKeyProvider
157157
public_key_provider = UrlPublicKeyProvider(self.App, public_keys_url)
158158
id_token_provider.register_key_provider(public_key_provider)
159+
else:
160+
public_key_provider = None
159161

160162
enabled = Config.get("auth", "enabled", fallback=True)
161163
if enabled == "mock":
162-
introspection_url = Config.get("auth", "introspection_url", fallback=None)
163-
if introspection_url:
164-
from .providers import AccessTokenAuthProvider
165-
provider = AccessTokenAuthProvider(self.App, introspection_url=introspection_url)
166-
provider.register_key_provider(public_key_provider)
167-
self.Providers.append(provider)
168-
else:
169-
from .providers import MockAuthProvider
170-
provider = MockAuthProvider(self.App, auth_claims_path=Config.get("auth", "mock_user_info_path"))
171-
self.Providers.append(provider)
164+
from .providers import MockAuthProvider
165+
provider = MockAuthProvider(self.App, auth_claims_path=Config.get("auth", "mock_user_info_path"))
166+
self.Providers.append(provider)
172167
return
173168

169+
elif enabled == "development":
170+
introspection_url = Config.get("auth", "introspection_url", fallback=None)
171+
if introspection_url is None or public_key_provider is None:
172+
raise ValueError(
173+
"AuthService is in development mode, but introspection_url or public_keys_url is not set."
174+
)
175+
176+
from .providers import AccessTokenAuthProvider
177+
provider = AccessTokenAuthProvider(self.App, introspection_url=introspection_url)
178+
provider.register_key_provider(public_key_provider)
179+
self.Providers.append(provider)
180+
174181
elif string_to_boolean(enabled) is False:
175182
raise ValueError(
176183
"Disabling AuthService is deprecated. "

0 commit comments

Comments
 (0)