Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cashu/mint/auth/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def _verify_decode_jwt(self, clear_auth_token: str) -> Any:
clear_auth_token,
signing_key.key,
algorithms=["RS256", "ES256"],
audience=settings.mint_auth_oicd_client_id,
issuer=self.issuer,
options={"verify_aud": False},
)
logger.trace(f"Decoded JWT: {decoded}")
# Bind the token to this mint's OIDC client. Keycloak puts the client
Expand Down
13 changes: 8 additions & 5 deletions tests/mint/test_mint_auth_server_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ def __init__(self, key):
assert decoded_no_azp["sub"] == "bob"


def test_verify_decode_jwt_rejects_mismatched_audience(monkeypatch):
def test_verify_decode_jwt_accepts_non_client_audience(monkeypatch):
import jwt
from cryptography.hazmat.primitives.asymmetric import rsa

from cashu.core.settings import settings

private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
public_key = private_key.public_key()

Expand All @@ -318,19 +320,20 @@ def __init__(self, key):

ledger.jwks_client = cast(Any, MockJWKSClient())

# Token with mismatched audience
# NUT-21 does not require access token audience to match the OIDC client id.
token = jwt.encode(
{
"iss": "https://issuer.test",
"aud": "wrong-client",
"aud": "account",
"azp": settings.mint_auth_oicd_client_id,
"sub": "alice",
},
private_key,
algorithm="RS256",
)

with pytest.raises(jwt.InvalidTokenError):
ledger._verify_decode_jwt(token)
decoded = ledger._verify_decode_jwt(token)
assert decoded["sub"] == "alice"


def test_verify_decode_jwt_rejects_mismatched_azp(monkeypatch):
Expand Down
Loading