Skip to content

Commit 25c1a27

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 9a1c482 + 53eedf8 commit 25c1a27

File tree

6 files changed

+58
-57
lines changed

6 files changed

+58
-57
lines changed

src/idpyoidc/server/oauth2/authorization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ def authn_args_gather(
268268

269269

270270
def check_unknown_scopes_policy(request_info, client_id, context):
271-
if not context.get_preference("deny_unknown_scopes"):
271+
cinfo = context.cdb.get(client_id, {})
272+
deny_unknown_scopes = cinfo.get("deny_unknown_scopes", context.get_preference("deny_unknown_scopes"))
273+
if not deny_unknown_scopes:
272274
return
273275

274276
scope = request_info["scope"]

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_24_oauth2_authorization_endpoint.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,38 @@ def test_setup_auth_invalid_scope(self):
588588
assert excp
589589
assert isinstance(excp, UnAuthorizedClientScope)
590590

591+
def test_setup_auth_invalid_scope_2(self):
592+
request = AuthorizationRequest(
593+
client_id="client_id",
594+
redirect_uri="https://rp.example.com/cb",
595+
response_type=["id_token"],
596+
state="state",
597+
nonce="nonce",
598+
scope="openid THAT-BLOODY_SCOPE",
599+
)
600+
cinfo = {
601+
"client_id": "client_id",
602+
"redirect_uris": [("https://rp.example.com/cb", {})],
603+
"id_token_signed_response_alg": "RS256",
604+
"allowed_scopes": ["openid", "profile", "email", "address", "phone", "offline_access"],
605+
"deny_unknown_scopes": True
606+
}
607+
608+
_context = self.endpoint.upstream_get("context")
609+
_context.cdb["client_id"] = cinfo
610+
611+
kaka = _context.cookie_handler.make_cookie_content("value", "sso")
612+
613+
# force to 400 Http Error message if the release scope policy is heavy!
614+
_context.set_preference("deny_unknown_scopes", False)
615+
excp = None
616+
try:
617+
res = self.endpoint.process_request(request, http_info={"headers": {"cookie": [kaka]}})
618+
except UnAuthorizedClientScope as e:
619+
excp = e
620+
assert excp
621+
assert isinstance(excp, UnAuthorizedClientScope)
622+
591623
def test_setup_auth_user(self):
592624
request = AuthorizationRequest(
593625
client_id="client_id",

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)