Skip to content

Commit 0ad7e98

Browse files
committed
Fix basic auth parsing when client id contains colon
add enable_oauth2_1 capability minor fixes minor fix
1 parent fd283e2 commit 0ad7e98

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/idpyoidc/server/client_authn.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Dict
55
from typing import Optional
66
from typing import Union
7+
from urllib.parse import unquote
78

89
from cryptojwt.exception import BadSignature
910
from cryptojwt.exception import Invalid
@@ -92,16 +93,17 @@ def is_usable(
9293
raise NotImplementedError()
9394

9495

95-
def basic_authn(authorization_token: str):
96-
if not authorization_token.startswith("Basic "):
96+
def basic_authn(authorization_header: str, urldecode_client_id_secret=False):
97+
if not authorization_header.startswith("Basic "):
9798
raise ClientAuthenticationError("Wrong type of authorization token")
9899

99-
_tok = as_bytes(authorization_token[6:])
100-
# Will raise ValueError type exception if not base64 encoded
101-
_tok = base64.b64decode(_tok)
102-
part = as_unicode(_tok).split(":", 1)
100+
_tok = base64.b64decode(authorization_header[6:].encode("utf-8"))
101+
part = _tok.decode("utf-8").split(":", 1)
102+
103103
if len(part) != 2:
104104
raise ValueError("Illegal token")
105+
if urldecode_client_id_secret:
106+
part = [unquote(p) for p in part]
105107

106108
return dict(zip(["id", "secret"], part))
107109

@@ -168,7 +170,9 @@ def _verify(
168170
endpoint=None, # Optional[Endpoint]
169171
**kwargs,
170172
):
171-
client_info = basic_authn(authorization_token)
173+
kwargs = getattr(endpoint, "kwargs", {}) or {}
174+
enable_oauth2_1 = kwargs.get("enable_oauth2_1", False)
175+
client_info = basic_authn(authorization_token, urldecode_client_id_secret=enable_oauth2_1)
172176
_context = self.upstream_get("context")
173177
if _context.cdb[client_info["id"]]["client_secret"] == client_info["secret"]:
174178
return {"client_id": client_info["id"]}

0 commit comments

Comments
 (0)