Spaces:
Paused
Paused
Mirrowel
commited on
Commit
·
3f8f2ac
1
Parent(s):
8aef79d
refactor(auth): refine duplicate OAuth credential checking logic
Browse filesupdate the structure used for tracking processed OAuth emails during application lifespan initialization.
- The tracking dictionary now stores `email -> {provider: path}` instead of just `email -> path`.
- This ensures that duplicate credential warnings are only logged when multiple files for the *same* provider and email are found.
- Prevents false duplicate warnings when a user provides credentials for the same email across different OAuth services (e.g., Google and Microsoft).
src/proxy_app/main.py
CHANGED
|
@@ -164,7 +164,7 @@ async def lifespan(app: FastAPI):
|
|
| 164 |
|
| 165 |
if not skip_oauth_init and oauth_credentials:
|
| 166 |
logging.info("Validating OAuth credentials and checking for duplicates...")
|
| 167 |
-
processed_emails = {}
|
| 168 |
for provider, paths in oauth_credentials.items():
|
| 169 |
provider_plugin_class = PROVIDER_PLUGINS.get(provider)
|
| 170 |
if not provider_plugin_class: continue
|
|
@@ -189,10 +189,13 @@ async def lifespan(app: FastAPI):
|
|
| 189 |
|
| 190 |
email = metadata.get("email")
|
| 191 |
if email:
|
| 192 |
-
if email in processed_emails:
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
| 194 |
else:
|
| 195 |
-
processed_emails[email] = path
|
| 196 |
except Exception as e:
|
| 197 |
logging.error(f"Failed to process OAuth token for {provider} at '{path}': {e}")
|
| 198 |
logging.info("OAuth credential processing complete.")
|
|
|
|
| 164 |
|
| 165 |
if not skip_oauth_init and oauth_credentials:
|
| 166 |
logging.info("Validating OAuth credentials and checking for duplicates...")
|
| 167 |
+
processed_emails = {} # email -> {provider: path}
|
| 168 |
for provider, paths in oauth_credentials.items():
|
| 169 |
provider_plugin_class = PROVIDER_PLUGINS.get(provider)
|
| 170 |
if not provider_plugin_class: continue
|
|
|
|
| 189 |
|
| 190 |
email = metadata.get("email")
|
| 191 |
if email:
|
| 192 |
+
if email not in processed_emails:
|
| 193 |
+
processed_emails[email] = {}
|
| 194 |
+
if provider in processed_emails[email]:
|
| 195 |
+
original_path = processed_emails[email][provider]
|
| 196 |
+
logging.warning(f"Duplicate credential for user '{email}' on provider '{provider}' found at '{Path(path).name}'. Original at '{Path(original_path).name}'.")
|
| 197 |
else:
|
| 198 |
+
processed_emails[email][provider] = path
|
| 199 |
except Exception as e:
|
| 200 |
logging.error(f"Failed to process OAuth token for {provider} at '{path}': {e}")
|
| 201 |
logging.info("OAuth credential processing complete.")
|
src/rotator_library/providers/gemini_auth_base.py
CHANGED
|
@@ -115,7 +115,6 @@ class GeminiAuthBase:
|
|
| 115 |
lib_logger.debug(f"Initializing Gemini token for '{file_name}'...")
|
| 116 |
try:
|
| 117 |
creds = await self._load_credentials(creds_or_path) if path else creds_or_path
|
| 118 |
-
|
| 119 |
reason = ""
|
| 120 |
if not creds.get("refresh_token"):
|
| 121 |
reason = "refresh token is missing"
|
|
|
|
| 115 |
lib_logger.debug(f"Initializing Gemini token for '{file_name}'...")
|
| 116 |
try:
|
| 117 |
creds = await self._load_credentials(creds_or_path) if path else creds_or_path
|
|
|
|
| 118 |
reason = ""
|
| 119 |
if not creds.get("refresh_token"):
|
| 120 |
reason = "refresh token is missing"
|