Skip to main content

🎭 Extract Microsoft OAuth tokens using Playwright browser automation.

Project description

🎭 Extract Microsoft OAuth tokens using Playwright browser automation.

📦 Installation

To install msauth-browser, you can use pip, pip3 or pipx. Either from pypi repository or from GitHub source. Prefer using pipx, since it install Python applications in isolated virtual environments.

From PyPI

pipx install msauth-browser
pip install msauth-browser

From GitHub

pip install "git+https://github.com/n3rada/msauth-browser"
pipx install "git+https://github.com/n3rada/msauth-browser"

Playwright

Ensure chromium playwright browser is available:

playwright install chromium

If installed with pipx:

  • Windows PowerShell
$env:NODE_TLS_REJECT_UNAUTHORIZED = "0"
& "$env:USERPROFILE\pipx\venvs\msauth-browser\Scripts\playwright.exe" install chromium

Usage

msauth-browser

Options:

  • --prt-cookie <JWT>: Use an x-ms-RefreshTokenCredential PRT cookie for SSO-based login.
  • --headless: Run Playwright in headless mode.
msauth-browser --headless --prt-cookie "<x-ms-RefreshTokenCredential>"

About the PRT Cookie

The PRT cookie is officially x-ms-RefreshTokenCredential and it is a JSON Web Token (JWT). The actual Primary Refresh Token (PRT) is encapsulated within the refresh_token, which is encrypted by a key under the control of Entra ID, rendering its contents opaque.

It can be used as a cookie wired to login.microsoftonline.com domain in order to use-it to authenticate to the service while skiping credential prompts.

Microsoft first-party apps

Microsoft first-party apps have hardcoded, pre-approved scopes.

You cannot simply add ChannelMessage.Read.All to the scope parameter of the Teams application, the request will fail.

Why not microsoft-authentication-library-for-python (MSAL)?

One major limitation is that it requires localhost redirect URIs.

MSAL documentation indicating localhost requirement

It also does not support integrating PRT cookies.

Adding new app presets

  1. Drop a JSON file into msauth_browser/configs/.
  2. Provide the required fields:
    • name
    • client_id
    • redirect_uri
    • default_scopes (array of scopes) — optional; if omitted or empty, the tool defaults to openid and offline_access.
  3. Optionally include a slug field; otherwise the filename (without extension) becomes the lookup key.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msauth_browser-0.2.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msauth_browser-0.2.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file msauth_browser-0.2.0.tar.gz.

File metadata

  • Download URL: msauth_browser-0.2.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.9 Linux/6.16.8+kali-amd64

File hashes

Hashes for msauth_browser-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b7a5a73d508461ac2482a28980ae09183cb9a20a626c4016518c1220aba5c570
MD5 0a14869726de343ad566596dbb27a890
BLAKE2b-256 13eb2842a02d420d5838f51f7241f19095ef7968927358afcd74db019df7a38b

See more details on using hashes here.

File details

Details for the file msauth_browser-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: msauth_browser-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.9 Linux/6.16.8+kali-amd64

File hashes

Hashes for msauth_browser-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2798e3e8ba42b039ed1fb7cdc9d499c8adf6f6e20b75be4091a19cd6dfea6978
MD5 df483854cb5c89ced346b185d50dc129
BLAKE2b-256 50be48baf409a4eadd3f0fafb4c50d3916d658cb6cd94aa102539540f9fe6ddd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page