Skip to content

Commit d249f81

Browse files
committed
Merge branch 'rfc9207' into 'main'
implement rfc9207 with authlib See merge request yaal/canaille!242
2 parents b74a845 + efd683b commit d249f81

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

canaille/oidc/endpoints/oauth.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import datetime
22
import uuid
33

4-
from authlib.common.urls import add_params_to_uri
54
from authlib.integrations.flask_oauth2 import current_token
65
from authlib.jose import jwt
76
from authlib.jose.errors import JoseError
@@ -151,15 +150,7 @@ def authorize_consent(client, user):
151150
)
152151

153152
if client_has_user_consent:
154-
response = authorization.create_authorization_response(grant_user=user)
155-
156-
# Manually implement RFC9207 until this is implemented upstream in authlib
157-
# https://github.com/lepture/authlib/pull/700
158-
response.location = add_params_to_uri(
159-
response.location, {"iss": get_issuer()}
160-
)
161-
162-
return response
153+
return authorization.create_authorization_response(grant_user=user)
163154

164155
elif request.args.get("prompt") == "none":
165156
response = {
@@ -172,9 +163,8 @@ def authorize_consent(client, user):
172163
try:
173164
grant = authorization.get_consent_grant(end_user=user)
174165
except OAuth2Error as error:
175-
response = {**dict(error.get_body()), "iss": get_issuer()}
176-
current_app.logger.debug("authorization endpoint response: %s", response)
177-
return jsonify(response)
166+
current_app.logger.debug("authorization endpoint response: %s", error)
167+
return {**dict(error.get_body()), "iss": get_issuer()}, error.status_code
178168

179169
form = AuthorizeForm(request.form or None)
180170
return render_template(
@@ -219,10 +209,6 @@ def authorize_consent(client, user):
219209

220210
response = authorization.create_authorization_response(grant_user=grant_user)
221211

222-
# Manually implement RFC9207 until this is implemented upstream in authlib
223-
# https://github.com/lepture/authlib/pull/700
224-
response.location = add_params_to_uri(response.location, {"iss": get_issuer()})
225-
226212
current_app.logger.debug("authorization endpoint response: %s", response.location)
227213
return response
228214

canaille/oidc/oauth.py

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from authlib.oauth2.rfc7636 import CodeChallenge as _CodeChallenge
2929
from authlib.oauth2.rfc7662 import IntrospectionEndpoint as _IntrospectionEndpoint
3030
from authlib.oauth2.rfc8414 import AuthorizationServerMetadata
31+
from authlib.oauth2.rfc9207.parameter import IssuerParameter as _IssuerParameter
3132
from authlib.oidc.core import UserInfo
3233
from authlib.oidc.core.grants import OpenIDCode as _OpenIDCode
3334
from authlib.oidc.core.grants import OpenIDHybridGrant as _OpenIDHybridGrant
@@ -629,6 +630,11 @@ def get_authorization_code_challenge_method(self, authorization_code):
629630
return authorization_code.challenge_method
630631

631632

633+
class IssuerParameter(_IssuerParameter):
634+
def get_issuer(self) -> str:
635+
return get_issuer()
636+
637+
632638
authorization = AuthorizationServer()
633639
require_oauth = ResourceProtector()
634640

@@ -677,6 +683,7 @@ def setup_oauth(app):
677683
authorization.register_grant(
678684
AuthorizationCodeGrant,
679685
[
686+
IssuerParameter(),
680687
OpenIDCode(require_nonce=app.config["CANAILLE_OIDC"]["REQUIRE_NONCE"]),
681688
CodeChallenge(required=True),
682689
],

tests/oidc/test_authorization_code_flow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def test_nonce_required_in_oidc_requests(testclient, logged_user, client):
617617
scope="openid profile",
618618
redirect_uri="https://client.test/redirect1",
619619
),
620-
status=200,
620+
status=400,
621621
)
622622

623623
assert res.json.get("error") == "invalid_request"

uv.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)