Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify retrieval of encrypted auth state #772

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions oauthenticator/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import jwt
from jupyterhub.auth import Authenticator
from jupyterhub.crypto import EncryptionUnavailable, InvalidToken, decrypt
from jupyterhub.handlers import BaseHandler, LogoutHandler
from jupyterhub.utils import url_path_join
from tornado import web
Expand Down Expand Up @@ -705,7 +704,7 @@ def _allowed_scopes_validation(self, proposal):
and SHOULD send the additional parameters as defined in Section 4 to
all servers.

Note that S256 is the only code challenge method supported. As per `section 4.2 of RFC 6749
Note that S256 is the only code challenge method supported. As per `section 4.2 of RFC 6749
<https://www.rfc-editor.org/rfc/rfc6749#section-3.1>`_:

If the client is capable of using "S256", it MUST use "S256", as
Expand Down Expand Up @@ -995,23 +994,12 @@ async def get_prev_refresh_token(self, handler, username):
Called by the :meth:`oauthenticator.OAuthenticator.authenticate`
"""
user = handler.find_user(username)
if not user or not user.encrypted_auth_state:
return

self.log.debug(
"Encrypted_auth_state was found, will try to decrypt and pull refresh_token from it..."
)

try:
encrypted = user.encrypted_auth_state
auth_state = await decrypt(encrypted)

return auth_state.get("refresh_token")
except (ValueError, InvalidToken, EncryptionUnavailable) as e:
self.log.warning(
f"Failed to retrieve encrypted auth_state for {username}. Error was {e}.",
)
return
if not user:
return None
auth_state = await user.get_auth_state()
if not auth_state:
return None
return auth_state.get("refresh_token", None)

def build_access_tokens_request_params(self, handler, data=None):
"""
Expand Down