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 lines135136137138139140141223 unmodified lines36536636736836937016 unmodified lines387388389390391392134 unmodified linesjson.dump(creds_data, f, indent=2)def get_credentials():"""Loads credentials matching gemini-cli OAuth2 flow."""global credentials, credentials_from_env, user_project_id223 unmodified lineslogging.error(f"Failed to read credentials file {CREDENTIAL_FILE}: {e}")# Fall through to new login only if file is completely unreadableclient_config = {"installed": {"client_id": CLIENT_ID,16 unmodified linesprompt="consent",include_granted_scopes='true')logging.info(f"Please open this URL in your browser to log in: {auth_url}")server = HTTPServer(("", 8080), _OAuthCallbackHandler)134 unmodified lines135136137138139140141223 unmodified lines36536636736836937037137237337437516 unmodified lines392393394395396397398399400401402403134 unmodified linesjson.dump(creds_data, f, indent=2)def get_credentials(allow_oauth_flow=True):"""Loads credentials matching gemini-cli OAuth2 flow."""global credentials, credentials_from_env, user_project_id223 unmodified lineslogging.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 allowedif not allow_oauth_flow:logging.info("OAuth flow not allowed - returning None (credentials will be required on first request)")return Noneclient_config = {"installed": {"client_id": CLIENT_ID,16 unmodified linesprompt="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 lines373839404142434445464748495051525354555636 unmodified linesasync def startup_event():try:logging.info("Starting Gemini proxy server...")creds = get_credentials()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")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("Could not obtain credentials. Please authenticate and restart the server.")except Exception as e:logging.error(f"Startup error: {str(e)}")logging.warning("Server may not function properly.")36 unmodified lines37383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929336 unmodified linesasync def startup_event():try:logging.info("Starting Gemini proxy server...")# Check if credentials existimport osfrom .config import CREDENTIAL_FILEenv_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 firstcreds = 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")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"Credential loading error: {str(e)}")logging.warning("Server started but credentials need to be set up.")else:# No credentials found - prompt user to authenticatelogging.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