Skip to content

Commit d9f8165

Browse files
Merge pull request #202 from c00kiemon5ter/feature-pyop-multiple-scopes
Support multiple scopes
2 parents 2de1c81 + 0312313 commit d9f8165

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

example/plugins/frontends/openid_connect_frontend.yaml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ config:
99
response_types_supported: ["code", "id_token token"]
1010
subject_types_supported: ["pairwise"]
1111
scopes_supported: ["openid", "email"]
12+
extra_scopes:
13+
foo_scope:
14+
- bar_claim
15+
- baz_claim

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
packages=find_packages('src/'),
1616
package_dir={'': 'src'},
1717
install_requires=[
18-
"pyop",
18+
"pyop >= 2.1.0",
1919
"pysaml2",
2020
"pycryptodomex",
2121
"requests",

src/satosa/frontends/openid_connect.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ def handle_authn_response(self, context, internal_resp, extra_id_token_claims=No
121121

122122
attributes = self.converter.from_internal("openid", internal_resp.attributes)
123123
self.user_db[internal_resp.subject_id] = {k: v[0] for k, v in attributes.items()}
124-
auth_resp = self.provider.authorize(auth_req, internal_resp.subject_id, extra_id_token_claims)
124+
auth_resp = self.provider.authorize(
125+
auth_req,
126+
internal_resp.subject_id,
127+
extra_id_token_claims=extra_id_token_claims,
128+
extra_scopes=self.config.get("extra_scopes"),
129+
)
125130

126131
del context.state[self.name]
127132
http_response = auth_resp.request(auth_req["redirect_uri"], should_fragment_encode(auth_req))
@@ -352,7 +357,11 @@ def userinfo_endpoint(self, context):
352357
headers = {"Authorization": context.request_authorization}
353358

354359
try:
355-
response = self.provider.handle_userinfo_request(urlencode(context.request), headers)
360+
response = self.provider.handle_userinfo_request(
361+
request=urlencode(context.request),
362+
http_headers=headers,
363+
extra_scopes=self.config.get("extra_scopes"),
364+
)
356365
return Response(response.to_json(), content="application/json")
357366
except (BearerTokenError, InvalidAccessToken) as e:
358367
error_resp = UserInfoErrorResponse(error='invalid_token', error_description=str(e))

tests/satosa/backends/test_openid_connect.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def test_entire_flow(self, context, backend_config, internal_attributes, userinf
192192
auth_params = dict(parse_qsl(urlparse(auth_response.message).query))
193193

194194
access_token = 12345
195-
context.request = {"state": auth_params["state"], "access_token": access_token}
195+
context.request = {
196+
"state": auth_params["state"],
197+
"access_token": access_token,
198+
"token_type": "Bearer",
199+
}
196200
self.oidc_backend.response_endpoint(context)
197201
assert self.oidc_backend.name not in context.state
198202
args = self.oidc_backend.auth_callback_func.call_args[0]

0 commit comments

Comments
 (0)