Skip to content

Commit

Permalink
Merge branch '222-kid' into 'main'
Browse files Browse the repository at this point in the history
fix: dynamic kid parameter for JWKs

Closes #222

See merge request yaal/canaille!227
  • Loading branch information
azmeuk committed Feb 5, 2025
2 parents 337d55e + 54a515d commit ca81e76
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Fixed
^^^^^
- Canaille executable did not support i18n. :issue:`227`
- Dynamic `kid` parameter for JWKs. :issue:`222`

[0.0.61] - 2025-02-04
---------------------
Expand Down
8 changes: 5 additions & 3 deletions canaille/oidc/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from authlib.integrations.flask_oauth2 import AuthorizationServer
from authlib.integrations.flask_oauth2 import ResourceProtector
from authlib.jose import JsonWebKey
from authlib.oauth2.rfc6749.grants import (
AuthorizationCodeGrant as _AuthorizationCodeGrant,
)
Expand Down Expand Up @@ -31,6 +30,7 @@
from flask import g
from flask import request
from flask import url_for
from joserfc.jwk import JWKRegistry
from werkzeug.security import gen_salt

from canaille.app import DOCUMENTATION_URL
Expand Down Expand Up @@ -150,12 +150,14 @@ def get_jwt_config(grant=None):
def get_jwks():
kty = current_app.config["CANAILLE_OIDC"]["JWT"]["KTY"]
alg = current_app.config["CANAILLE_OIDC"]["JWT"]["ALG"]
jwk = JsonWebKey.import_key(
current_app.config["CANAILLE_OIDC"]["JWT"]["PUBLIC_KEY"], {"kty": kty}
jwk = JWKRegistry.import_key(
current_app.config["CANAILLE_OIDC"]["JWT"]["PUBLIC_KEY"], kty
)
jwk.ensure_kid()
return {
"keys": [
{
"kid": jwk.kid,
"use": "sig",
"alg": alg,
**jwk,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ front = [

oidc = [
"authlib >= 1.3.0",
"joserfc>=1.0.2",
]

scim = [
Expand Down
3 changes: 3 additions & 0 deletions tests/oidc/test_jwks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import mock

from authlib.jose import JsonWebKey


Expand All @@ -9,6 +11,7 @@ def test_jwks(testclient, keypair):
assert res.json == {
"keys": [
{
"kid": mock.ANY,
"use": "sig",
"alg": "RS256",
**jwk,
Expand Down
14 changes: 14 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca81e76

Please sign in to comment.