Skip to main content

galeo

Verify Galeo access tokens in Python services, map Galeo roles onto your own, and test all of it without a network.

It's the backend half of adding "Sign in with Galeo" to an app. The frontend half is @galeo/react, which signs the user in and sends their access token on every API call.

pip install "galeo[fastapi]"

Configure

Two values, both from the application's page in the Galeo admin console:

GALEO_ISSUER https://<host>/auth/<organization>, for the host your users sign in on
GALEO_CLIENT_ID The application's client ID

GALEO_SCOPE is optional and defaults to openid profile email groups.

from galeo import GaleoConfig

config = GaleoConfig.from_env()
# or GaleoConfig(issuer="https://login.example.com/auth/acme", client_id="…")

FastAPI

from fastapi import Depends, FastAPI
from galeo import GaleoConfig, Principal
from galeo.fastapi import Galeo

app = FastAPI()
galeo = Galeo(GaleoConfig.from_env())

# GET /auth/config: what the frontend needs to start sign-in.
app.include_router(galeo.config_router())


@app.get("/me")
def me(principal: Principal = Depends(galeo.principal)):
    return {"id": principal.subject, "email": principal.email, "roles": sorted(principal.roles)}


@app.delete("/projects/{project_id}")
def delete_project(
    project_id: str, principal: Principal = Depends(galeo.require_role("admin"))
): ...
  • galeo.principal answers 401 with an RFC 6750 WWW-Authenticate challenge when the token is missing or invalid.
  • If Galeo can't be reached and no signing keys are cached yet, it answers 503. That's an outage, not a bad token, so clients retry instead of signing the user out.
  • galeo.optional_principal returns None when there's no token.
  • galeo.require_role(...) answers 403 unless the user holds one of the roles.

WebSockets

Browsers can't set Authorization on a WebSocket, so send the token as a subprotocol with new WebSocket(url, ["bearer", token]):

@app.websocket("/ws")
async def ws(websocket: WebSocket):
    principal = await galeo.websocket_principal(websocket)  # closes with 1008 if invalid
    await websocket.accept(subprotocol="bearer")

What gets checked

TokenVerifier.verify(token) accepts a token only if all of these hold:

  • Signature: checked with the key its kid names; RS256 only.
  • Token type: typ is at+jwt. Galeo's ID tokens are signed with the same key and carry the same sub and aud, so they're refused here.
  • Issuer: iss is your organization's issuer.
  • Audience: aud is your client ID. Every app in the organization shares the issuer and signing key, so without this check another app's token would pass, carrying the roles it holds in that other app.
  • Validity window: exp and nbf are current, allowing 30 seconds of skew.

Galeo's discovery document and keys are cached for as long as Galeo's Cache-Control allows.

  • Unknown kid: a token naming a key the cache doesn't have triggers a refetch, but at most once a minute, so garbage tokens can't make your service hammer Galeo.
  • Outages: if Galeo is unreachable, the last keys fetched stay in use.

The Principal

subject The user's Galeo ID. Stable for the life of the account.
key (issuer, subject). Key your local user records on this, not on email. An email can change, and a different account can later hold it.
email, name With the email / profile scopes
roles The user's role names in your application, from the groups claim. Not directory groups. Narrowed to the chosen role if the app makes users pick one at sign-in.
scopes Granted scopes
claims, token The raw claims and token

Creating local users on first sign-in

def current_user(
    principal: Principal = Depends(galeo.principal), db: Session = Depends(get_db)
) -> User:
    user = (
        db.query(User)
        .filter_by(galeo_issuer=principal.issuer, galeo_subject=principal.subject)
        .one_or_none()
    )
    if user is None:
        user = User(galeo_issuer=principal.issuer, galeo_subject=principal.subject)
        db.add(user)
    user.email, user.name = principal.email, principal.name
    user.role = roles.resolve(principal.roles)
    db.commit()
    return user

Mapping roles

from galeo import RoleMapper

roles = RoleMapper(
    {"admin": "admin", "program-lead": "lead"},  # Galeo role -> your role
    ranking=["admin", "lead", "contributor"],  # most to least privileged
    default="contributor",
)
roles.resolve(principal.roles)  # "admin", "lead" or "contributor"

Resolve on every sign-in and store the result. Don't only ever raise a stored role: someone removed from a role in Galeo has to lose it in your app too.

Testing your app

import pytest
from galeo.testing import FakeGaleo
from myapp.main import app, galeo


@pytest.fixture
def fake_galeo():
    fake = FakeGaleo(client_id="my-app")
    fake.install(galeo)  # the app's Galeo now trusts the fake's tokens
    return fake


def test_me(fake_galeo):
    token = fake_galeo.access_token(roles=["admin"], email="ada@example.test")
    res = TestClient(app).get("/me", headers={"Authorization": f"Bearer {token}"})
    assert res.json()["roles"] == ["admin"]

FakeGaleo serves discovery and JWKS in memory, so the real verification path runs. To build tokens that must be refused, push an argument out of range:

  • expires_in=-60 for an expired token
  • audience="another-app" for another app's token
  • typ="JWT" for an ID token

rotate_key() simulates a key rotation.

Development

pip install -e ".[dev]"
pytest
ruff check . && mypy

Metadata

Release files for galeo 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for galeo 0.1.0
File Size Uploaded Provenance Actions
galeo-0.1.0.tar.gz 20.7 kB With provenance Details for galeo-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for galeo 0.1.0
File Interpreter ABI Platform Actions
galeo-0.1.0-py3-none-any.whl Python 3 none any Details for galeo-0.1.0-py3-none-any.whl

Total release size: 41.6 kB

Release files / galeo-0.1.0.tar.gz

Download URL galeo-0.1.0.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3c787fa0e94c1907c3885375bd5be109fbcbb7e98ed199d61618675146e970f3
BLAKE2b-256 checksum
How to use checksums
c59417dad0c94a593a304b46569ddd53614b2026394343afcfbfe2a69578f912
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 29, 2026.

Transparency log

Release files / galeo-0.1.0-py3-none-any.whl

Download URL galeo-0.1.0-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
885a11989d26d5bd15ba74f44145407d7543eeafd3435c72887ecdc6feb68b4a
BLAKE2b-256 checksum
How to use checksums
6c7046b3e902eb6121ddc4d4e7383cb065d9928a337ca32387c69a97abe91538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 29, 2026.

Transparency log

Security for galeo 0.1.0

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.

Select from 2 files

Attestation for galeo-0.1.0.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 Sep 29, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page