Check, on your server, the access tokens your Rante app's frontend gets from
Rante.getAccessToken(), and find out
who and which tenant each request is for. Built on PyJWT. Python 3.10 or later.
What a token contains and what is checked: docs/tokens.md. The same checks, error codes and test cases exist for Node.js, .NET, Java, Go and PHP.
Status: 0.1.0. Rante's hosting of apps is being built to this design; tokens are issued once it is live.
From GitHub (not published to PyPI yet):
pip install "rante-apps-sdk @ git+https://github.com/rante-corporation/rante-apps-sdk-python"from rante_apps import RanteAppTokenVerifier, RanteAppsError, get_bearer_token # One verifier per app, created once: it caches Rante Login's signing keys and is thread-safe. verifier = RanteAppTokenVerifier("3f2b8c1e-7d4a-4e9b-a6c5-1d2e3f4a5b6c") try: principal = verifier.verify(get_bearer_token(request.headers.get("Authorization")) or "") except RanteAppsError as error: ... # answer error.status, with error.www_authenticate as the WWW-Authenticate header principal.user_id # the person (oid) principal.tenant_id # the customer's tenant (tid) principal.scopes # what the tenant granted, e.g. ('user.read', 'tenant.read', 'auth.token')
Your pages should send Content-Security-Policy: frame-ancestors https://portal.rante.com (the constant
FRAME_ANCESTORS) so that only Rante can frame them.
| Keyword | Default | |
|---|---|---|
client_id |
(required, first argument) | Your app's Application (client) ID. |
tenants |
any tenant | Accept tokens of these tenants only (tenant_not_allowed otherwise). |
required_scopes |
none | Scopes every token must have (insufficient_scope otherwise). |
extra_audiences |
none | Audiences accepted besides the client ID, such as api://{client_id}. |
authority |
https://login.rante.com |
http is accepted for localhost only, for tests. |
clock_skew |
60 |
Seconds of clock difference tolerated for exp, nbf and iat. |
algorithms |
("RS256",) |
RS256 and ES256 are supported. |
timeout |
5.0 |
Seconds for each request to Rante Login. |
jwks_cooldown |
30.0 |
Minimum seconds between two key fetches (an unknown kid triggers one). |
jwks_max_age |
600.0 |
Seconds fetched keys are used before they are fetched again. |
http_get |
urllib | (url, timeout) -> bytes, for proxies or tests. |
RanteAppPrincipal is a frozen dataclass: user_id (oid), tenant_id (tid), subject (sub: stable, different for
every app), name, username (preferred_username), email, app_id (your client ID), authorized_party (azp),
scopes (from scp), roles, issued_at, expires_at (aware datetimes in UTC), issuer and claims (read-only).
verify raises RanteAppsError with code one of missing_token, invalid_token, token_expired (401),
tenant_not_allowed, insufficient_scope (403), discovery_failed, network_error (503) or
invalid_configuration (500). error.status is that HTTP status and error.www_authenticate the header value to
send with it (or None).
examples/flask is a complete external app on Flask: a page that asks Rante for a token and an
/api/me endpoint that checks it (see require_rante in app.py).
cd examples/flask pip install -e ../.. -r requirements.txt RANTE_CLIENT_ID=<your-app-id> python app.py
Rante opens external apps from an https:// address, so register the server behind one in
manifest.json.
pip install -e ".[test]"
pytesttests/conformance/tokens.json is a copy of
conformance/tokens.json: the
cases every server SDK passes. The tests sign them with keys generated for the run and serve those keys from a local
stand-in for Rante Login; nothing leaves the machine.
MIT. Report security problems privately through this repository's Security tab.