Skip to content

Commit 8231bd9

Browse files
authored
Merge pull request #72 from ctriant/userinfo-unbind-auth-event
Unbind authentication event lifetime from userinfo response
2 parents 9faec70 + 2293ba5 commit 8231bd9

File tree

2 files changed

+14
-54
lines changed

2 files changed

+14
-54
lines changed

src/idpyoidc/server/oidc/userinfo.py

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -133,44 +133,22 @@ def process_request(self, request=None, **kwargs):
133133
if token.is_active() is False:
134134
return self.error_cls(error="invalid_token", error_description="Invalid Token")
135135

136-
allowed = True
137-
_auth_event = _grant.authentication_event
138-
# if the authentication is still active or offline_access is granted.
139-
if not _auth_event["valid_until"] >= utc_time_sans_frac():
140-
logger.debug(
141-
"authentication not valid: {} > {}".format(
142-
datetime.fromtimestamp(_auth_event["valid_until"]),
143-
datetime.fromtimestamp(utc_time_sans_frac()),
144-
)
145-
)
146-
allowed = False
147-
148-
# This has to be made more fine grained.
149-
# if "offline_access" in session["authn_req"]["scope"]:
150-
# pass
151-
152-
if allowed:
153-
_cntxt = self.upstream_get("context")
154-
_claims_restriction = _cntxt.claims_interface.get_claims(
155-
_session_info["branch_id"], scopes=token.scope, claims_release_point="userinfo"
156-
)
157-
info = _cntxt.claims_interface.get_user_claims(
158-
_session_info["user_id"], claims_restriction=_claims_restriction
159-
)
160-
info["sub"] = _grant.sub
161-
if _grant.add_acr_value("userinfo"):
162-
info["acr"] = _grant.authentication_event["authn_info"]
136+
_cntxt = self.upstream_get("context")
137+
_claims_restriction = _cntxt.claims_interface.get_claims(
138+
_session_info["branch_id"], scopes=token.scope, claims_release_point="userinfo"
139+
)
140+
info = _cntxt.claims_interface.get_user_claims(
141+
_session_info["user_id"], claims_restriction=_claims_restriction
142+
)
143+
info["sub"] = _grant.sub
144+
if _grant.add_acr_value("userinfo"):
145+
info["acr"] = _grant.authentication_event["authn_info"]
163146

164-
if "userinfo" in _cntxt.cdb[request["client_id"]]:
165-
self.config["policy"] = _cntxt.cdb[request["client_id"]]["userinfo"]["policy"]
147+
if "userinfo" in _cntxt.cdb[request["client_id"]]:
148+
self.config["policy"] = _cntxt.cdb[request["client_id"]]["userinfo"]["policy"]
166149

167-
if "policy" in self.config:
168-
info = self._enforce_policy(request, info, token, self.config)
169-
else:
170-
info = {
171-
"error": "invalid_request",
172-
"error_description": "Access not granted",
173-
}
150+
if "policy" in self.config:
151+
info = self._enforce_policy(request, info, token, self.config)
174152

175153
return {"response_args": info, "client_id": _session_info["client_id"]}
176154

tests/test_server_26_oidc_userinfo_endpoint.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,6 @@ def test_process_request(self):
310310
args = self.endpoint.process_request(_req, http_info=http_info)
311311
assert args
312312

313-
def test_process_request_not_allowed(self):
314-
session_id = self._create_session(AUTH_REQ)
315-
grant = self.session_manager[session_id]
316-
code = self._mint_code(grant, session_id)
317-
access_token = self._mint_token("access_token", grant, session_id, code)
318-
319-
# 2 things can make the request invalid.
320-
# 1) The token is not valid anymore or 2) The event is not valid.
321-
_event = grant.authentication_event
322-
_event["authn_time"] -= 9000
323-
_event["valid_until"] -= 9000
324-
325-
http_info = {"headers": {"authorization": "Bearer {}".format(access_token.value)}}
326-
_req = self.endpoint.parse_request({}, http_info=http_info)
327-
328-
args = self.endpoint.process_request(_req, http_info=http_info)
329-
assert set(args["response_args"].keys()) == {"error", "error_description"}
330-
331313
def test_do_response(self):
332314
session_id = self._create_session(AUTH_REQ)
333315
grant = self.session_manager[session_id]

0 commit comments

Comments
 (0)