Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 3cef583

Browse files
committed
Apply id_token claims from the auth request to issued ID Token.
1 parent afdde3e commit 3cef583

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/oidcop/oidc/userinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def process_request(self, request=None, **kwargs):
144144
if _claims:
145145
_acr_request = _claims.get("acr")
146146
if _acr_request:
147-
if claims_match(_grant.authentication_event["authn_info"], _acr):
147+
if claims_match(_grant.authentication_event["authn_info"], _acr_request):
148148
info["acr"] = _grant.authentication_event["authn_info"]
149149
else:
150150
info = {

src/oidcop/session/grant.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from oidcop.authn_event import AuthnEvent
1111
from oidcop.session import MintingNotAllowed
12+
from oidcop.session.claims import claims_match
1213
from oidcop.session.token import AccessToken
1314
from oidcop.session.token import AuthorizationCode
1415
from oidcop.session.token import IDToken
@@ -221,6 +222,13 @@ def payload_arguments(
221222
user_info = endpoint_context.claims_interface.get_user_claims(user_id, _claims_restriction)
222223
payload.update(user_info)
223224

225+
# Should I add the acr value
226+
_release = self.claims.get(claims_release_point)
227+
if _release:
228+
_acr_request = _release.get("acr")
229+
if claims_match(self.authentication_event["authn_info"], _acr_request):
230+
payload["acr"] = self.authentication_event["authn_info"]
231+
224232
return payload
225233

226234
def mint_token(

tests/test_05_id_token.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ def full_path(local_file):
115115
"acr": INTERNETPROTOCOLPASSWORD,
116116
"class": "oidcop.user_authn.user.NoAuthn",
117117
"kwargs": {"user": "diana"},
118+
},
119+
"mfa": {
120+
"acr": 'https://refeds.org/profile/mfa',
121+
"class": "oidcop.user_authn.user.NoAuthn",
122+
"kwargs": {"user": "diana"},
118123
}
119124
},
120125
"session_manager": {
@@ -170,15 +175,15 @@ def create_session_manager(self):
170175
self.session_manager = self.endpoint_context.session_manager
171176
self.user_id = USER_ID
172177

173-
def _create_session(self, auth_req, sub_type="public", sector_identifier=""):
178+
def _create_session(self, auth_req, sub_type="public", sector_identifier="", authn_info=''):
174179
if sector_identifier:
175180
authz_req = auth_req.copy()
176181
authz_req["sector_identifier_uri"] = sector_identifier
177182
else:
178183
authz_req = auth_req
179184

180185
client_id = authz_req["client_id"]
181-
ae = create_authn_event(self.user_id)
186+
ae = create_authn_event(self.user_id, authn_info=authn_info)
182187
return self.session_manager.create_session(
183188
ae, authz_req, self.user_id, client_id=client_id, sub_type=sub_type
184189
)
@@ -587,3 +592,20 @@ def test_id_token_info(self):
587592
get_sign_and_encrypt_algorithms(
588593
endpoint_context, client_info, payload_type="id_token", sign=True, encrypt=True
589594
)
595+
596+
def test_id_token_acr_claim(self):
597+
_req = AREQS.copy()
598+
_req["claims"] = {"id_token": {"acr": {"value": "https://refeds.org/profile/mfa"}}}
599+
600+
session_id = self._create_session(_req,authn_info="https://refeds.org/profile/mfa")
601+
grant = self.session_manager[session_id]
602+
code = self._mint_code(grant, session_id)
603+
access_token = self._mint_access_token(grant, session_id, code)
604+
605+
id_token = self._mint_id_token(
606+
grant, session_id, token_ref=code, access_token=access_token.value
607+
)
608+
609+
_jwt = factory(id_token.value)
610+
_id_token_content = _jwt.jwt.payload()
611+
assert _id_token_content["acr"] == "https://refeds.org/profile/mfa"

0 commit comments

Comments
 (0)