fix: EdDSA to Ed25519 token migration#786
Conversation
aldbr
left a comment
There was a problem hiding this comment.
That looks good, thank you 🙂
I just have a few minor comments around the tests.
Next step: making sure there is a documentation page to rotate the keys (and delete old ones if needed). If it does not exist, then we need to create one based on #499 (comment)
TODOs:Rotation:
How to check rotation:
|
|
joserfc error breaking the demo when trying to login as diracAdmin:
Full Logs: See: https://jose.authlib.org/en/guide/errors/#unsupportedalgorithmerror |
Tried to match their tests logic in our code: def create_token(payload: TokenPayload, settings: AuthSettings) -> str:
"""Create a JWT token with the given payload and settings."""
signing_key = None
for key in settings.token_keystore.jwks.keys:
key_ops = key.get("key_ops")
if key_ops and not isinstance(key_ops, list):
key_ops = [key_ops]
if key_ops and "sign" in key_ops:
signing_key = key
break
if not signing_key:
raise ValueError("No signing key found in JWKS")
# test logic here
algorithms = ["Ed25519"]
encoded_jwt = jwt.encode({"alg": "Ed25519"}, {}, signing_key, algorithms=algorithms)
jwt.decode(encoded_jwt, signing_key, algorithms=algorithms)Still the same error. What their {
"crv": "Ed25519",
"x": "t-nFRaxyM5DZcpg5lxiEeJcZpMRB8JgcKaQC0HRefXU",
"d": "gUF17HCe-pbN7Ej2rDSXl-e7uSj7rQW5u2dNu0KINP0",
"kty": "OKP",
"kid": "5V_IcL-iX5IbaNz9vg0CjXtWLZiJ94-ESnHI-HN1L2Y"
}Our {
"crv": "Ed25519",
"x": "OgKojQ4lAhaRjU_KF1vNkv99dnu8GRuDwkhdiAdsSJc",
"d": "skcpv4O3AR5GvITk2AA84H8AfhzXoth49TKTlE_dusM",
"key_ops": [
"sign",
"verify"
],
"alg": "Ed25519",
"kid": "019c4d8717dc75b1afc74172281b3b75",
"kty": "OKP"
} |
|
Tried to test the different keys @pytest.mark.parametrize(
"key", [
# joserfc key
({"crv": "Ed25519", "x": "t-nFRaxyM5DZcpg5lxiEeJcZpMRB8JgcKaQC0HRefXU", "d": "gUF17HCe-pbN7Ej2rDSXl-e7uSj7rQW5u2dNu0KINP0", "kty": "OKP", "kid": "5V_IcL-iX5IbaNz9vg0CjXtWLZiJ94-ESnHI-HN1L2Y"}),
# dirac key
({"crv": "Ed25519", "x": "OgKojQ4lAhaRjU_KF1vNkv99dnu8GRuDwkhdiAdsSJc", "d": "skcpv4O3AR5GvITk2AA84H8AfhzXoth49TKTlE_dusM", "key_ops": ["sign","verify"], "alg": "Ed25519", "kid": "019c4d8717dc75b1afc74172281b3b75", "kty": "OKP"})
]
)
def test_dummy(key):
from joserfc.jwk import OKPKey
from joserfc import jwt
ed25519_key = OKPKey.import_key(key)
algorithms = ["Ed25519"]
encoded_jwt = jwt.encode({"alg": "Ed25519"}, {}, ed25519_key, algorithms=algorithms)
jwt.decode(encoded_jwt, ed25519_key, algorithms=algorithms)Both test passed. Maybe Edit: |
cc @aldbr
Closes: #718
Changes:
TODO: