Skip to content

Commit 3c2abdc

Browse files
authored
Merge pull request #820 from minrk/fix-scope
[All] fix parsing of scope, often required for github email address
2 parents f7e085a + f5876c3 commit 3c2abdc

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

oauthenticator/oauth2.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,16 @@ def build_auth_state_dict(self, token_info, user_info):
12001200
id_token = token_info.get("id_token", None)
12011201
scope = token_info.get("scope", "")
12021202

1203+
# scope is a nonstandard field
1204+
# sometimes list, sometimes space-delimited str like the request,
1205+
# sometimes comma-delimited str (github)
12031206
if isinstance(scope, str):
1204-
scope = scope.split(" ")
1207+
if " " in scope:
1208+
scope = scope.split(" ")
1209+
elif "," in scope:
1210+
scope = scope.split(",")
1211+
else:
1212+
scope = [scope]
12051213

12061214
return {
12071215
"access_token": access_token,

oauthenticator/tests/test_github.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def github_client(client):
3333
access_token_path='/login/oauth/access_token',
3434
user_path='/user',
3535
token_type='token',
36+
scope="user:email,read:org",
3637
)
3738
return client
3839

@@ -135,6 +136,7 @@ async def test_github(
135136
assert set(auth_model) == {"name", "admin", "auth_state"}
136137
assert auth_model["admin"] == expect_admin
137138
auth_state = auth_model["auth_state"]
139+
assert auth_state["scope"] == ["user:email", "read:org"]
138140
assert json.dumps(auth_state)
139141
assert "access_token" in auth_state
140142
user_info = auth_state[authenticator.user_auth_state_key]

0 commit comments

Comments
 (0)