Skip to content

Instantly share code, notes, and snippets.

@eidosam
Created October 16, 2025 10:53
Show Gist options
  • Select an option

  • Save eidosam/beecc1e347a882df86eac219587b8b8a to your computer and use it in GitHub Desktop.

Select an option

Save eidosam/beecc1e347a882df86eac219587b8b8a to your computer and use it in GitHub Desktop.
Extracts the Airflow authentication token from a local Chrome profile using Selenium and accesses the Airflow REST API
import shutil
import tempfile
import time
from pathlib import Path
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
airflow_url = 'https://airflow...'
profile_name = 'Default'
profile_path = f'{Path.home()}/Library/Application Support/Google/Chrome/{profile_name}'
temp_dir = tempfile.mkdtemp()
temp_profile_path = f'{temp_dir}/{profile_name}'
shutil.copytree(profile_path, temp_profile_path)
if __name__ == '__main__':
chrome_options = Options()
chrome_options.add_argument(f'--user-data-dir={temp_dir}')
chrome_options.add_argument(f'--profile-directory={profile_name}')
driver = webdriver.Chrome(options=chrome_options)
driver.get(airflow_url)
time.sleep(10)
auth_token = driver.execute_script('return window.localStorage.getItem("token");')
driver.quit()
print(auth_token)
airflow_api_base_url = f'{airflow_url}/api/v2'
headers = {
'Authorization': f'Bearer {auth_token}'
}
res = requests.get(f'{airflow_api_base_url}/dags', headers=headers)
print(res.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment