From f0a2601f047dbeeb5f7df9ae60a35ff4a8627a42 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Mon, 22 Jan 2024 15:09:50 -0800 Subject: [PATCH 1/2] Suggest possible config fix when correct scopes aren't requested If the hub config doesn't contain appropriate scopes to request from the provider, the token we retrieve may not have the key we are using as `username_claim`. This is the *most common* reason that `username_claim` is not present in the token. Add a simple debugging hint here to make lives of hub admins easier. --- oauthenticator/oauth2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauthenticator/oauth2.py b/oauthenticator/oauth2.py index 9ba66ecf..170689fe 100644 --- a/oauthenticator/oauth2.py +++ b/oauthenticator/oauth2.py @@ -770,7 +770,7 @@ def user_info_to_username(self, user_info): """ username = user_info.get(self.username_claim, None) if not username: - message = (f"No {self.username_claim} found in {user_info}",) + message = (f"No {self.username_claim} found in {user_info}. Maybe the hub needs to be configured to request more scopes?",) self.log.error(message) raise ValueError(message) From 77eb6d16683a8d4df968cf4c24cd475bc4c31435 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:11:44 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- oauthenticator/oauth2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oauthenticator/oauth2.py b/oauthenticator/oauth2.py index 170689fe..71560dbd 100644 --- a/oauthenticator/oauth2.py +++ b/oauthenticator/oauth2.py @@ -770,7 +770,9 @@ def user_info_to_username(self, user_info): """ username = user_info.get(self.username_claim, None) if not username: - message = (f"No {self.username_claim} found in {user_info}. Maybe the hub needs to be configured to request more scopes?",) + message = ( + f"No {self.username_claim} found in {user_info}. Maybe the hub needs to be configured to request more scopes?", + ) self.log.error(message) raise ValueError(message)