Skip to content

Commit d3db6a6

Browse files
authored
Merge pull request #76 from IdentityPython/develop
A couple of fixes
2 parents 869068c + 8231bd9 commit d3db6a6

File tree

4 files changed

+23
-56
lines changed

4 files changed

+23
-56
lines changed

src/idpyoidc/server/oauth2/token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,4 @@ def process_request(self, request: Optional[Union[Message, dict]] = None, **kwar
189189
return resp
190190

191191
def supports(self):
192-
return {"grant_types_supported": list(self.grant_type_helper.keys())}
192+
return self._supports

src/idpyoidc/server/oidc/token.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ class Token(token.Token):
2626
name = "token"
2727
default_capabilities = None
2828

29+
helper_by_grant_type = {
30+
"authorization_code": AccessTokenHelper,
31+
"refresh_token": RefreshTokenHelper,
32+
"urn:ietf:params:oauth:grant-type:token-exchange": TokenExchangeHelper,
33+
}
34+
2935
_supports = {
3036
"token_endpoint_auth_methods_supported": [
3137
"client_secret_post",
3238
"client_secret_basic",
3339
"client_secret_jwt",
3440
"private_key_jwt",
3541
],
36-
"token_endpoint_auth_signing_alg_values_supported": claims.get_signing_algs,
42+
"token_endpoint_auth_signing_alg_values_supported": claims.get_signing_algs(),
43+
"grant_types_supported": list(helper_by_grant_type.keys())
3744
}
3845

3946
helper_by_grant_type = {

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)