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

Commit e51c3d5

Browse files
committed
Handle scopes inside policy callable
1 parent 5609a07 commit e51c3d5

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/oidcop/oidc/token.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,15 @@ def post_parse_request(self, request, client_id="", **kwargs):
424424

425425
token = _mngr.find_token(_session_info["session_id"], request["subject_token"])
426426

427-
error = self.enforce_policy(request, token)
428-
if error is not None:
429-
return error
427+
resp = self.enforce_policy(request, token)
428+
if isinstance(resp, TokenErrorResponse):
429+
return resp
430430

431431
if token.is_active() is False:
432432
return self.error_cls(
433433
error="invalid_request", error_description="Subject token inactive"
434434
)
435-
return request
435+
return resp
436436

437437
def enforce_policy(self, request, token):
438438
_context = self.endpoint.server_get("endpoint_context")
@@ -599,21 +599,14 @@ def default_token_exchange_policy(request, context, kwargs):
599599
error="invalid_target", error_description="Unknown audience"
600600
)
601601

602-
# TODO: if requested type is jwt make sure our tokens are jwt
603-
# if (
604-
# "requested_token_type" in request
605-
# and request["requested_token_type"] not in kwargs["token_types_allowed"]
606-
# ):
607-
# return TokenErrorResponse(
608-
# error="invalid_target",
609-
# error_description="Unsupported requested token type"
610-
# )
611-
612602
if "actor_token" in request or "actor_token_type" in request:
613603
return TokenErrorResponse(
614604
error="invalid_request", error_description="Actor token not supported"
615605
)
616606

607+
request["scope"] = kwargs.get("scope", ["openid"])
608+
return request
609+
617610
class Token(oauth2.token.Token):
618611
request_cls = Message
619612
response_cls = oidc.AccessTokenResponse

tests/test_36_oauth2_token_exchange.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,23 @@ def create_endpoint(self):
130130
"kwargs": {
131131
"audience": ["https://example.com"],
132132
"resource": [],
133-
"scopes": ["abc", "def"]
133+
"scope": ["openid"]
134134
}
135135
},
136136
"urn:ietf:params:oauth:token-type:refresh_token": {
137137
"callable": "oidcop.oidc.token.default_token_exchange_policy",
138138
"kwargs": {
139139
"audience": ["https://example.com"],
140140
"resource": [],
141-
"scopes": ["abc", "def"]
141+
"scope": ["openid"]
142142
}
143143
},
144144
"": {
145145
"callable": "oidcop.oidc.token.default_token_exchange_policy",
146146
"kwargs": {
147147
"audience": ["https://example.com"],
148148
"resource": [],
149-
"scopes": ["abc", "def"]
149+
"scope": ["openid"]
150150
}
151151
},
152152
},

0 commit comments

Comments
 (0)