tokentoss
OAuth authentication from Jupyter notebooks for IAP-protected GCP services.
Features
- anywidget with "Sign in with Google" button
- Authorization Code flow with PKCE for security and refresh tokens
- Token persistence across sessions
- IAPClient for authenticated HTTP requests with auto-refresh
Installation
pip install tokentoss
Or with uv:
uv add tokentoss
Quick Start
1. One-Time GCP Setup
- Create a Desktop OAuth client in GCP Console
- Download
client_secrets.json - Add the Desktop client ID to your IAP's programmatic access allowlist
- Grant yourself the "IAP-secured Web App User" role
2. Configure Credentials
Use the ConfigureWidget for a password-safe setup (credentials never appear in notebook source):
from tokentoss import ConfigureWidget
display(ConfigureWidget())
# Enter Client ID and Client Secret, click "Configure"
Or configure programmatically:
import tokentoss
tokentoss.configure(client_id="YOUR_CLIENT_ID", client_secret="YOUR_SECRET")
Credentials are stored to ~/.config/tokentoss/client_secrets.json so they stay out of version control.
3. Authenticate in Jupyter
from tokentoss import GoogleAuthWidget
# Widget auto-discovers credentials from the standard config location
widget = GoogleAuthWidget()
display(widget)
# Click "Sign in with Google" and complete the flow
# Widget shows "Signed in as user@example.com"
4. Make Authenticated Requests
from tokentoss import IAPClient
# Create client (auto-discovers credentials)
client = IAPClient(base_url="https://my-iap-service.run.app")
# Make requests - ID token added automatically
data = client.get_json("/api/data")
response = client.post("/api/items", json={"name": "test"})
How It Works
configure()stores OAuth client credentials to a standard platform location- Widget opens a popup for Google OAuth
- User authenticates and grants consent
- AuthManager exchanges auth code for tokens (with PKCE)
- Tokens are stored securely (file permissions 0600)
- IAPClient uses ID token for IAP authentication
- Tokens refresh automatically when expired
Development
# Clone and install
git clone https://github.com/NicholasGrundl/tokentoss.git
cd tokentoss
uv sync --group dev
# Run tests
uv run pytest
# Lint and format
uv run ruff format src/ tests/
uv run ruff check src/ tests/
# Type check (advisory)
uv run ty check src/
# Start Jupyter for testing
uv run jupyter lab
License
MIT
Metadata
Release files for tokentoss 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokentoss-0.1.1.tar.gz | 322.8 kB | With provenance | Details for tokentoss-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokentoss-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for tokentoss-0.1.1-py3-none-any.whl |
Total release size: 349.0 kB
Release files / tokentoss-0.1.1.tar.gz
| Download URL | tokentoss-0.1.1.tar.gz |
|---|---|
| Size | 322.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc5c371d94fa3589642dcd85e84f07f497a697e63c16138ca876a10a2b28d92d
|
|
BLAKE2b-256 checksum How to use checksums |
0600de9fb1e95ba05fb907290d237dcda053abcbf8076fe52d5c4e52ec1c4e0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.
Transparency logRelease files / tokentoss-0.1.1-py3-none-any.whl
| Download URL | tokentoss-0.1.1-py3-none-any.whl |
|---|---|
| Size | 26.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
371e3e26162db6afdeed9e5f656dad150cdebb7b44d5bae59e73511ae62fc406
|
|
BLAKE2b-256 checksum How to use checksums |
9c3eb9ecc74a90ed765fdf11517f6465dfda3712dc06b2421fe61d5a2a5297a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.
Transparency logSecurity for tokentoss 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tokentoss-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.