refac
This commit is contained in:
@@ -18,7 +18,7 @@ import jwt
|
||||
from authlib.integrations.starlette_client import OAuth
|
||||
from authlib.oauth2.rfc6749.errors import OAuth2Error
|
||||
from authlib.oidc.core import UserInfo
|
||||
from cryptography.fernet import Fernet
|
||||
from cryptography.fernet import Fernet, InvalidToken
|
||||
from fastapi import (
|
||||
HTTPException,
|
||||
status,
|
||||
@@ -275,12 +275,8 @@ def encrypt_data(data) -> str:
|
||||
|
||||
def decrypt_data(data: str):
|
||||
"""Decrypt data from storage"""
|
||||
try:
|
||||
decrypted = FERNET.decrypt(data.encode()).decode()
|
||||
return JSONCodec.loads(decrypted)
|
||||
except Exception as e:
|
||||
log.error(f'Error decrypting data: {e}')
|
||||
raise
|
||||
decrypted = FERNET.decrypt(data.encode()).decode()
|
||||
return JSONCodec.loads(decrypted)
|
||||
|
||||
|
||||
def _build_oauth_callback_error_message(e: Exception) -> str:
|
||||
@@ -909,8 +905,19 @@ class OAuthClientManager:
|
||||
oauth_client_info = await recover_static_oauth_client_metadata(connection, oauth_client_info)
|
||||
oauth_client_info = apply_connection_oauth_options(connection, oauth_client_info)
|
||||
return self.add_client(expected_client_id, OAuthClientInformationFull(**oauth_client_info))['client']
|
||||
except InvalidToken:
|
||||
log.error(
|
||||
'Failed to lazily add OAuth client %s from config: InvalidToken. '
|
||||
'Stored OAuth client data is invalid; reconnect this tool server.',
|
||||
expected_client_id,
|
||||
)
|
||||
continue
|
||||
except Exception as e:
|
||||
log.error(f'Failed to lazily add OAuth client {expected_client_id} from config: {e}')
|
||||
log.error(
|
||||
'Failed to lazily add OAuth client %s from config: %s',
|
||||
expected_client_id,
|
||||
f'{type(e).__name__}: {e}' if str(e) else type(e).__name__,
|
||||
)
|
||||
continue
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user