OAuth authentication from Jupyter notebooks for IAP-protected GCP services
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokentoss-0.1.0.tar.gz.
File metadata
- Download URL: tokentoss-0.1.0.tar.gz
- Upload date:
- Size: 329.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46bc244e35d2c21399526c64f843fdafc8e8bfe06cb865578e2c574d2de0828e
|
|
| MD5 |
f75007fabfac01ab7fee3ed7d362c360
|
|
| BLAKE2b-256 |
064256fea1c5190ba5287952f6dcec589801bd1ecb9bb9cff3eae5869ecf38c1
|
Provenance
The following attestation bundles were made for tokentoss-0.1.0.tar.gz:
Publisher:
release.yml on NicholasGrundl/tokentoss
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokentoss-0.1.0.tar.gz -
Subject digest:
46bc244e35d2c21399526c64f843fdafc8e8bfe06cb865578e2c574d2de0828e - Sigstore transparency entry: 909526875
- Sigstore integration time:
-
Permalink:
NicholasGrundl/tokentoss@b6f69d62fe0328fb0bd38ff280bdaf2b4f81e758 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/NicholasGrundl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6f69d62fe0328fb0bd38ff280bdaf2b4f81e758 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tokentoss-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tokentoss-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a46727cdd81e834f58815c8df5b6d4e22a77e615545ed370bf6dbbff086f53b
|
|
| MD5 |
3724cddb36409d018f2c303d9743642c
|
|
| BLAKE2b-256 |
26069cafb623542cfe5f5ec24c0edf7ae063a717b4470ef5f3880655b8c25caa
|
Provenance
The following attestation bundles were made for tokentoss-0.1.0-py3-none-any.whl:
Publisher:
release.yml on NicholasGrundl/tokentoss
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokentoss-0.1.0-py3-none-any.whl -
Subject digest:
6a46727cdd81e834f58815c8df5b6d4e22a77e615545ed370bf6dbbff086f53b - Sigstore transparency entry: 909526884
- Sigstore integration time:
-
Permalink:
NicholasGrundl/tokentoss@b6f69d62fe0328fb0bd38ff280bdaf2b4f81e758 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/NicholasGrundl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b6f69d62fe0328fb0bd38ff280bdaf2b4f81e758 -
Trigger Event:
push
-
Statement type: