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

Commit afdde3e

Browse files
committed
Apply userinfo claims from the auth request to response from the userinfo endpoint.
1 parent afa043e commit afdde3e

2 files changed

Lines changed: 59 additions & 29 deletions

File tree

src/oidcop/oidc/userinfo.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from oidcmsg import oidc
1111
from oidcmsg.message import Message
1212
from oidcmsg.oauth2 import ResponseMessage
13+
from oidcop.session.claims import claims_match
1314

1415
from oidcop.endpoint import Endpoint
1516
from oidcop.token.exception import UnknownToken
@@ -140,6 +141,11 @@ def process_request(self, request=None, **kwargs):
140141
user_id=_session_info["user_id"], claims_restriction=_claims
141142
)
142143
info["sub"] = _grant.sub
144+
if _claims:
145+
_acr_request = _claims.get("acr")
146+
if _acr_request:
147+
if claims_match(_grant.authentication_event["authn_info"], _acr):
148+
info["acr"] = _grant.authentication_event["authn_info"]
143149
else:
144150
info = {
145151
"error": "invalid_request",

tests/test_26_oidc_userinfo_endpoint.py

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import json
22
import os
33

4-
from oidcop.configure import OPConfiguration
5-
import pytest
64
from oidcmsg.oauth2 import ResponseMessage
75
from oidcmsg.oidc import AccessTokenRequest
86
from oidcmsg.oidc import AuthorizationRequest
97
from oidcmsg.time_util import time_sans_frac
8+
import pytest
109

1110
from oidcop import user_info
1211
from oidcop.authn_event import create_authn_event
12+
from oidcop.configure import OPConfiguration
1313
from oidcop.cookie_handler import CookieHandler
1414
from oidcop.oidc import userinfo
1515
from oidcop.oidc.authorization import Authorization
@@ -105,8 +105,8 @@ def create_endpoint(self):
105105
"class": ProviderConfiguration,
106106
"kwargs": {},
107107
},
108-
"registration": {"path": "registration", "class": Registration, "kwargs": {},},
109-
"authorization": {"path": "authorization", "class": Authorization, "kwargs": {},},
108+
"registration": {"path": "registration", "class": Registration, "kwargs": {}, },
109+
"authorization": {"path": "authorization", "class": Authorization, "kwargs": {}, },
110110
"token": {
111111
"path": "token",
112112
"class": Token,
@@ -123,7 +123,7 @@ def create_endpoint(self):
123123
"path": "userinfo",
124124
"class": userinfo.UserInfo,
125125
"kwargs": {
126-
"claim_types_supported": ["normal", "aggregated", "distributed",],
126+
"claim_types_supported": ["normal", "aggregated", "distributed", ],
127127
"client_authn_method": ["bearer_header"],
128128
},
129129
},
@@ -138,7 +138,13 @@ def create_endpoint(self):
138138
"acr": INTERNETPROTOCOLPASSWORD,
139139
"class": "oidcop.user_authn.user.NoAuthn",
140140
"kwargs": {"user": "diana"},
141+
},
142+
"mfa": {
143+
"acr": "https://refeds.org/profile/mfa",
144+
"class": "oidcop.user_authn.user.NoAuthn",
145+
"kwargs": {"user": "diana"},
141146
}
147+
142148
},
143149
"template_dir": "template",
144150
"add_on": {
@@ -172,14 +178,15 @@ def create_endpoint(self):
172178
self.session_manager = endpoint_context.session_manager
173179
self.user_id = "diana"
174180

175-
def _create_session(self, auth_req, sub_type="public", sector_identifier=""):
181+
def _create_session(self, auth_req, sub_type="public", sector_identifier="",
182+
authn_info=None):
176183
if sector_identifier:
177184
authz_req = auth_req.copy()
178185
authz_req["sector_identifier_uri"] = sector_identifier
179186
else:
180187
authz_req = auth_req
181188
client_id = authz_req["client_id"]
182-
ae = create_authn_event(self.user_id)
189+
ae = create_authn_event(self.user_id, authn_info=authn_info)
183190
return self.session_manager.create_session(
184191
ae, authz_req, self.user_id, client_id=client_id, sub_type=sub_type
185192
)
@@ -210,28 +217,28 @@ def test_init(self):
210217
assert set(
211218
self.endpoint.server_get("endpoint_context").provider_info["claims_supported"]
212219
) == {
213-
"address",
214-
"birthdate",
215-
"email",
216-
"email_verified",
217-
"eduperson_scoped_affiliation",
218-
"family_name",
219-
"gender",
220-
"given_name",
221-
"locale",
222-
"middle_name",
223-
"name",
224-
"nickname",
225-
"phone_number",
226-
"phone_number_verified",
227-
"picture",
228-
"preferred_username",
229-
"profile",
230-
"sub",
231-
"updated_at",
232-
"website",
233-
"zoneinfo",
234-
}
220+
"address",
221+
"birthdate",
222+
"email",
223+
"email_verified",
224+
"eduperson_scoped_affiliation",
225+
"family_name",
226+
"gender",
227+
"given_name",
228+
"locale",
229+
"middle_name",
230+
"name",
231+
"nickname",
232+
"phone_number",
233+
"phone_number_verified",
234+
"picture",
235+
"preferred_username",
236+
"profile",
237+
"sub",
238+
"updated_at",
239+
"website",
240+
"zoneinfo",
241+
}
235242

236243
def test_parse(self):
237244
session_id = self._create_session(AUTH_REQ)
@@ -373,3 +380,20 @@ def test_invalid_token(self):
373380

374381
assert isinstance(args, ResponseMessage)
375382
assert args["error_description"] == "Invalid Token"
383+
384+
def test_userinfo_claims(self):
385+
_auth_req = AUTH_REQ.copy()
386+
_auth_req["claims"] = {"userinfo": {"acr": {"value": "https://refeds.org/profile/mfa"}}}
387+
388+
session_id = self._create_session(_auth_req, authn_info="https://refeds.org/profile/mfa")
389+
grant = self.session_manager[session_id]
390+
code = self._mint_code(grant, session_id)
391+
access_token = self._mint_token("access_token", grant, session_id, code)
392+
393+
http_info = {"headers": {"authorization": "Bearer {}".format(access_token.value)}}
394+
_req = self.endpoint.parse_request({}, http_info=http_info)
395+
396+
args = self.endpoint.process_request(_req)
397+
assert args
398+
res = self.endpoint.do_response(request=_req, **args)
399+
assert res

0 commit comments

Comments
 (0)