GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rante-corporation/rante-apps-sdk-python: Rante Apps server SDK for Python: verify the access tokens Rante.getAccessToken() gives your app, on PyJWT.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples/flask
examples/flask
 
 
src/rante_apps
src/rante_apps
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

Rante Apps server SDK for Python

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.

Install

From GitHub (not published to PyPI yet):

pip install "rante-apps-sdk @ git+https://github.com/rante-corporation/rante-apps-sdk-python"

Use

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.

Options

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.

The principal

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

Errors

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

Example

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.

Tests

pip install -e ".[test]"
pytest

tests/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.

License

MIT. Report security problems privately through this repository's Security tab.

About

Rante Apps server SDK for Python: verify the access tokens Rante.getAccessToken() gives your app, on PyJWT.

Topics

access-tokenjwtpythonrantesdk

Resources

Readme
MIT license

Code of conduct

Code of conduct

Security policy

Security policy
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.