Skip to content

Commit

Permalink
Merge pull request #772 from minrk/simplify-auth-state
Browse files Browse the repository at this point in the history
Simplify retrieval of encrypted auth state
  • Loading branch information
manics authored Oct 17, 2024
2 parents 2626322 + d1a84f9 commit 1bd5928
Showing 1 changed file with 7 additions and 19 deletions.
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

0 comments on commit 1bd5928

Please sign in to comment.