pyobs-auth 2.0.0.dev0__tar.gz → 2.0.0.dev2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyobs-auth
3
- Version: 2.0.0.dev0
3
+ Version: 2.0.0.dev2
4
4
  Summary: Shared Keycloak/OIDC authentication client for pyobs web services
5
5
  Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
6
6
  License-Expression: MIT
@@ -5,6 +5,9 @@ support here. See pyobs-core's shared-auth design doc for why: any upstream iden
5
5
  (including a self-hosted observation-portal) is meant to be brokered *behind* Keycloak, not
6
6
  validated directly by this class, so archive/robotic-backend/etc. only ever need to trust one
7
7
  issuer.
8
+
9
+ This class is written to be safe to stack alongside another Bearer-scheme authenticator that
10
+ can't be modified (e.g. an existing legacy OAuth2 BearerAuthentication) - see below.
8
11
  """
9
12
 
10
13
  from __future__ import annotations
@@ -29,6 +32,15 @@ class KeycloakAuthentication(authentication.BaseAuthentication):
29
32
  settings = get_settings()
30
33
  validator = TokenValidator(settings)
31
34
 
35
+ # DRF stops the whole authenticator chain on a raise, unlike a `None` return, which just
36
+ # falls through to the next class. If another Bearer-scheme authenticator is also
37
+ # registered (e.g. a legacy OAuth2 BearerAuthentication that can't be modified to do the
38
+ # same check), a token that was never meant for us must not block it from getting a turn -
39
+ # so defer (return None) for anything that doesn't even claim to be from our issuer, and
40
+ # only raise once we know the token was meant for us but is actually invalid.
41
+ if validator.unverified_issuer(token) != settings.issuer:
42
+ return None
43
+
32
44
  try:
33
45
  claims = validator.validate(token)
34
46
  except TokenValidationError as exc:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyobs-auth"
3
- version = "2.0.0.dev0"
3
+ version = "2.0.0.dev2"
4
4
  description = "Shared Keycloak/OIDC authentication client for pyobs web services"
5
5
  authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
6
6
  requires-python = ">=3.11"
File without changes