11"""DRF authentication that validates a third-party OIDC token against its provider's JWKS.
22
3- The token arrives as a ``Bearer`` token or as the password in a ``Basic`` header (``docker login``).
4- On success its claims map to grants and a stateless ``WorkloadIdentityPrincipal`` is returned.
3+ The token arrives as a ``Bearer`` token, or as the password of a ``Basic`` header whose username
4+ is the reserved workload-identity name. On success its claims map to grants and a stateless
5+ ``WorkloadIdentityPrincipal`` is returned.
56"""
67
78import base64
@@ -28,7 +29,12 @@ class WorkloadIdentityAuthentication(BaseAuthentication):
2829 """
2930
3031 def _get_token (self , request ):
31- """Return the token from the Authorization header (Bearer, or Basic password), or None."""
32+ """Return the token from the Authorization header, or None.
33+
34+ Accepts a ``Bearer`` token, or a token carried as the password of a ``Basic`` header whose
35+ username is the reserved workload-identity name. Any other ``Basic`` header is left for the
36+ regular authenticators.
37+ """
3238 header = request .META .get ("HTTP_AUTHORIZATION" , "" )
3339 parts = header .split ()
3440 if len (parts ) != 2 :
@@ -42,9 +48,9 @@ def _get_token(self, request):
4248 decoded = base64 .b64decode (value ).decode ("utf-8" )
4349 except (binascii .Error , ValueError , UnicodeDecodeError ):
4450 return None
45- if ":" not in decoded :
51+ username , sep , password = decoded .partition (":" )
52+ if not sep or username != config .basic_username ():
4653 return None
47- _ , _ , password = decoded .partition (":" )
4854 return password
4955 return None
5056
0 commit comments