Commit ·
4fe6125
1
Parent(s): c86a50e
fixed login link not showing
Browse filesFiles changed (2)
- src/auth.py+12-1
- src/main.py+48-11
134 unmodified lines135136137138138139140141223 unmodified lines36536636736836937037137237337437516 unmodified lines392393394395396397398399400401402403134 unmodified lines json.dump(creds_data, f, indent=2)
def get_credentials():def get_credentials(allow_oauth_flow=True): """Loads credentials matching gemini-cli OAuth2 flow.""" global credentials, credentials_from_env, user_project_id 223 unmodified lines logging.error(f"Failed to read credentials file {CREDENTIAL_FILE}: {e}") # Fall through to new login only if file is completely unreadable
# Only start OAuth flow if explicitly allowed if not allow_oauth_flow: logging.info("OAuth flow not allowed - returning None (credentials will be required on first request)") return None
client_config = { "installed": { "client_id": CLIENT_ID,16 unmodified lines prompt="consent", include_granted_scopes='true' ) print(f"\n{'='*80}") print(f"AUTHENTICATION REQUIRED") print(f"{'='*80}") print(f"Please open this URL in your browser to log in:") print(f"{auth_url}") print(f"{'='*80}\n") logging.info(f"Please open this URL in your browser to log in: {auth_url}") server = HTTPServer(("", 8080), _OAuthCallbackHandler)36 unmodified lines373839404140414243444546474849505152534344454647485455565758596061626364655051666768536970717273747576777879808182838485868788899091929336 unmodified linesasync def startup_event(): try: logging.info("Starting Gemini proxy server...") creds = get_credentials() if creds: # Check if credentials exist import os from .config import CREDENTIAL_FILE env_creds_json = os.getenv("GEMINI_CREDENTIALS") creds_file_exists = os.path.exists(CREDENTIAL_FILE) if env_creds_json or creds_file_exists: try: # Try to load existing credentials without OAuth flow first creds = get_credentials(allow_oauth_flow=False) if creds: try: proj_id = get_user_project_id(creds) if proj_id: onboard_user(creds, proj_id) logging.info(f"Successfully onboarded with project ID: {proj_id}") logging.info("Gemini proxy server started successfully") logging.info("Authentication required - Password: see .env file") proj_id = get_user_project_id(creds) if proj_id: onboard_user(creds, proj_id) logging.info(f"Successfully onboarded with project ID: {proj_id}") logging.info("Gemini proxy server started successfully") logging.info("Authentication required - Password: see .env file") except Exception as e: logging.error(f"Setup failed: {str(e)}") logging.warning("Server started but may not function properly until setup issues are resolved.") else: logging.warning("Credentials file exists but could not be loaded. Server started - authentication will be required on first request.") except Exception as e: logging.error(f"Setup failed: {str(e)}") logging.warning("Server started but may not function properly until setup issues are resolved.") logging.error(f"Credential loading error: {str(e)}") logging.warning("Server started but credentials need to be set up.") else: logging.error("Could not obtain credentials. Please authenticate and restart the server.") # No credentials found - prompt user to authenticate logging.info("No credentials found. Starting OAuth authentication flow...") try: creds = get_credentials(allow_oauth_flow=True) if creds: try: proj_id = get_user_project_id(creds) if proj_id: onboard_user(creds, proj_id) logging.info(f"Successfully onboarded with project ID: {proj_id}") logging.info("Gemini proxy server started successfully") except Exception as e: logging.error(f"Setup failed: {str(e)}") logging.warning("Server started but may not function properly until setup issues are resolved.") else: logging.error("Authentication failed. Server started but will not function until credentials are provided.") except Exception as e: logging.error(f"Authentication error: {str(e)}") logging.warning("Server started but authentication failed.") logging.info("Authentication required - Password: see .env file") except Exception as e: logging.error(f"Startup error: {str(e)}") logging.warning("Server may not function properly.")src/auth.py+12-1
src/main.py+48-11