Skip to content

Commit 79e547f

Browse files
committed
refactor: OIDC token scopes are stored as lists
1 parent fd77bd5 commit 79e547f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

canaille/oidc/endpoints.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def jwks():
216216
@require_oauth("profile")
217217
def userinfo():
218218
current_app.logger.debug("userinfo endpoint request: %s", request.args)
219-
response = generate_user_info(current_token.subject, current_token.scope[0])
219+
response = generate_user_info(current_token.subject, current_token.scope)
220220
current_app.logger.debug("userinfo endpoint response: %s", response)
221221
return jsonify(response)
222222

canaille/oidc/oauth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def save_token(token, request):
281281
access_token=token["access_token"],
282282
issue_date=now,
283283
lifetime=token["expires_in"],
284-
scope=token["scope"],
284+
scope=token["scope"].split(" "),
285285
client=request.client,
286286
refresh_token=token.get("refresh_token"),
287287
subject=request.user,

tests/oidc/test_authorization_code_flow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_authorization_code_flow(
7171
token = models.Token.get(access_token=access_token)
7272
assert token.client == client
7373
assert token.subject == logged_user
74-
assert set(token.scope[0].split(" ")) == {
74+
assert set(token.scope) == {
7575
"openid",
7676
"profile",
7777
"email",
@@ -760,7 +760,7 @@ def test_authorization_code_request_scope_too_large(
760760
token = models.Token.get(access_token=access_token)
761761
assert token.client == other_client
762762
assert token.subject == logged_user
763-
assert set(token.scope[0].split(" ")) == {
763+
assert set(token.scope) == {
764764
"openid",
765765
"profile",
766766
}

tests/oidc/test_userinfo.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_userinfo(testclient, token, user, foo_group):
155155
status=403,
156156
)
157157

158-
token.scope = ["openid profile"]
158+
token.scope = ["openid", "profile"]
159159
token.save()
160160
res = testclient.get(
161161
"/oauth/userinfo",
@@ -171,7 +171,7 @@ def test_userinfo(testclient, token, user, foo_group):
171171
"website": "https://john.example",
172172
}
173173

174-
token.scope = ["openid profile email"]
174+
token.scope = ["openid", "profile", "email"]
175175
token.save()
176176
res = testclient.get(
177177
"/oauth/userinfo",
@@ -188,7 +188,7 @@ def test_userinfo(testclient, token, user, foo_group):
188188
"email": "[email protected]",
189189
}
190190

191-
token.scope = ["openid profile address"]
191+
token.scope = ["openid", "profile", "address"]
192192
token.save()
193193
res = testclient.get(
194194
"/oauth/userinfo",
@@ -205,7 +205,7 @@ def test_userinfo(testclient, token, user, foo_group):
205205
"address": "1235, somewhere",
206206
}
207207

208-
token.scope = ["openid profile phone"]
208+
token.scope = ["openid", "profile", "phone"]
209209
token.save()
210210
res = testclient.get(
211211
"/oauth/userinfo",
@@ -222,7 +222,7 @@ def test_userinfo(testclient, token, user, foo_group):
222222
"phone_number": "555-000-000",
223223
}
224224

225-
token.scope = ["openid profile groups"]
225+
token.scope = ["openid", "profile", "groups"]
226226
token.save()
227227
res = testclient.get(
228228
"/oauth/userinfo",

0 commit comments

Comments
 (0)