scitex_browser.auth

scitex_browser.auth - Authentication helpers for browser automation.

Provides reusable authentication handlers for various OAuth providers and login flows used in browser automation tasks.

Features: - Google OAuth (popup-based flow) - Django session auth - Generic credential management

Example

from scitex_browser.auth import GoogleAuthHelper, google_login

# Quick login success = await google_login(page, “user@gmail.com”, “password”)

# Or with helper class auth = GoogleAuthHelper(email=”user@gmail.com”, password=”password”) success = await auth.login_via_google_button(page)

class scitex_browser.auth.GoogleAuthHelper(email=None, password=None, debug=False)[source]

Bases: object

Google OAuth authentication helper.

Handles the popup-based Google OAuth flow used by many services.

Environment Variables:

GOOGLE_EMAIL: Default email if not provided GOOGLE_PASSWORD: Default password if not provided

__init__(email=None, password=None, debug=False)[source]

Initialize GoogleAuthHelper.

Parameters:
  • email (Optional[str]) – Google account email

  • password (Optional[str]) – Google account password

  • debug (bool) – Print debug messages to stderr

_log(msg)[source]

Print debug message if debug mode is enabled.

async login_via_google_button(page, google_button_selector='button:has-text("Continue with Google")', timeout=60000)[source]

Perform Google OAuth login via a “Continue with Google” button.

This handles the popup-based OAuth flow: 1. Click the Google button on the main page 2. Handle the Google popup for email/password entry 3. Wait for redirect back to the original service

Parameters:
  • page (Page) – Playwright Page object (the main page with the Google button)

  • google_button_selector (str) – CSS selector for the Google login button

  • timeout (int) – Maximum time to wait for login (ms)

Return type:

bool

Returns:

True if login successful, False otherwise

async _handle_google_popup(popup, timeout=60000)[source]

Handle the Google OAuth popup flow.

Parameters:
  • popup (Page) – The Google OAuth popup page

  • timeout (int) – Maximum time to wait (ms)

Return type:

bool

Returns:

True if authentication successful, False otherwise

async _fill_email(popup)[source]

Fill email on Google login page.

Return type:

bool

async _fill_password(popup)[source]

Fill password on Google login page.

Return type:

bool

Handle OAuth consent or ‘Continue’ screens that may appear.

Return type:

None

async _wait_for_2fa(popup, timeout=60000)[source]

Wait for 2FA verification to complete.

Detects 2FA screens and waits for user to approve on their device.

Parameters:
  • popup (Page) – The Google OAuth popup page

  • timeout (int) – Maximum time to wait for 2FA (ms)

Return type:

bool

Returns:

True if 2FA completed, False if timed out

async is_logged_in(page, login_indicators=None)[source]

Check if user appears to be logged in.

Parameters:
  • page (Page) – Page to check

  • login_indicators (list) – List of URL substrings that indicate NOT logged in (default: [“login”, “signin”, “oauth”])

Return type:

bool

Returns:

True if appears logged in, False otherwise

async scitex_browser.auth.google_login(page, email, password, button_selector='button:has-text("Continue with Google")', debug=False)[source]

Quick Google OAuth login.

Parameters:
  • page (Page) – Playwright Page with Google login button

  • email (str) – Google account email

  • password (str) – Google account password

  • button_selector (str) – CSS selector for Google button

  • debug (bool) – Print debug messages

Return type:

bool

Returns:

True if login successful, False otherwise

Example

success = await google_login(page, “user@gmail.com”, “password”)