oidcauthlib
OIDC userinfo scopes (OidcUserInfoManager)
Some providers (e.g. Okta employee access tokens) only carry openid profile email groups in the JWT;
the scopes that authorize a caller appear only on the OIDC userinfo response.
oidcauthlib.auth.userinfo.oidc_userinfo_manager.OidcUserInfoManager resolves a token's effective
scopes from the token's own claims plus the userinfo endpoint, and caches the userinfo-derived scopes in
a key-value store.
manager = OidcUserInfoManager(
auth_config_reader=auth_config_reader,
well_known_configuration_manager=well_known_configuration_manager,
store=store, # py-key-value-aio store; yours, not shared with other services
cache_collection="oidc-user-info-cache",
cache_ttl_seconds=86400,
fetch_timeout_seconds=30,
scope_claims=["custom:scope"], # optional extra claims holding scopes
group_claims=["groups"], # optional claims holding group names, used whole as scopes
scope_remove_prefixes=["fhir/prod/"],
)
scopes = await manager.get_scopes_from_user_info_async(access_token=token)
- Scope derivation follows fhir-server-ui's
jwtParser: thescopeclaim (plusscp), thenscope_claims, thengroup_claims(each value taken whole). Commas separate like spaces, results are de-duplicated, andscope_remove_prefixesare stripped (first match wins). Nothing beyondscope/scpis read unless configured. - Provider is matched to the token's
iss: an exactissuer, else awell_known_urion the same scheme, host and port whose path segments start with the issuer's. Only a token with noissat all is matched by its client id. A token matching no provider raisesValueError; it is never sent to another provider. - Subject check: for a token that has a
sub, the userinfo response must carry the samesub(OIDC Core 5.3.2); a missing or different one raisesValueErrorand nothing is cached. - Cache key is
oidc-userinfo-scopes:<issuer>:<client_id>:<sub>|v1with each segment percent-encoded (so values containing:cannot collide, and two providers never share an entry); only the userinfo-derived scopes are stored, never the userinfo response. The token's own scopes are re-derived on every call. A token withoutsubor without an issuer, or an empty scope list, is not cached. Changes to a user's entitlements are visible after at mostcache_ttl_seconds. - Failures: the cache never fails a lookup. A write failure is logged and swallowed; a read failure or a malformed entry is logged and treated as a miss, and the refetched scopes overwrite the bad entry. A userinfo HTTP error, a missing provider or a mismatched subject is raised, so each service decides whether to fail closed or degrade.
Administrator and tenant-reader tiers (oidcauthlib.authorization)
Pure helpers that turn a caller's merged scopes (for example the result of OidcUserInfoManager) into a
tier: admin (unrestricted), reader (limited to the client keys its access/<slug>.* scopes select), or
denied. The subpackage reads no environment variable, does no I/O and imports nothing else from
oidcauthlib; the caller verifies the token, looks up the user and passes the configuration in.
from oidcauthlib.authorization import (
ClientSlugResolver,
parse_client_keys_lenient,
resolve_admin_access,
validate_reader_configuration,
)
RAW_CLIENTS = "One=key-1,Two=key-2" # the setting that holds the client-key mapping
# At startup: refuse an unsafe configuration (a no-op when no reader scopes are set).
validate_reader_configuration(
reader_scopes=["example/reader"],
admin_scopes=["example/admin"],
client_keys_raw=RAW_CLIENTS,
)
clients = ClientSlugResolver.from_client_keys(clients=parse_client_keys_lenient(raw=RAW_CLIENTS))
access = resolve_admin_access(
scopes=["example/reader", "access/one.*"],
admin_scopes=["example/admin"],
reader_scopes=["example/reader"],
clients=clients,
allow_all_tenants=False,
)
# access.tier is AdminTier.READER and access.allowed_client_keys == frozenset({"key-1"})
- Order: any
patient/scope (trimmed, case-insensitive) denies first; then holding every admin scope givesadmin; then every reader scope plus at least oneaccess/<slug>.*that selects a client givesreader; anything else is denied with aDenialReason. An empty admin or reader requirement admits nobody. - Slugs:
access/<slug>.*selects the client whose name, stripped and casefolded, equals the slug. Two names that casefold alike make the slug ambiguous and it selects nothing. The suffix must be exactly.*.access/*.*selects every client only whenallow_all_tenants=True. - No default for "all tenants":
allowed_client_keysisNoneonly foradmin. A reader always has a non-empty set and a denied caller always hasfrozenset(), so a denial can never be read as unrestricted.AdminAccessenforces this when it is constructed. - Client-key mapping: a
name -> keymap given as a JSON object orOne=key-1,Two=key-2.parse_client_keys_lenientkeeps the permissive behavior (a malformed JSON object falls back to comma parsing, an entry without=is dropped);parse_client_keys_strictrefuses both, and refuses blank or repeated names. Error messages name the rule, never a name or key. - Eligibility:
from_client_keys(..., is_eligible=...)takes a(name, key) -> boolstrategy for callers that exclude some clients; an excluded client is in no view and takes no part in ambiguity.
Metadata
Release files for oidcauthlib 3.1.0
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 |
|---|---|---|---|---|
| oidcauthlib-3.1.0.tar.gz | 94.2 kB | Without provenance | Details for oidcauthlib-3.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oidcauthlib-3.1.0-py3-none-any.whl | Python 3 | none | any | Details for oidcauthlib-3.1.0-py3-none-any.whl |
Total release size: 217.3 kB
Release files / oidcauthlib-3.1.0.tar.gz
| Download URL | oidcauthlib-3.1.0.tar.gz |
|---|---|
| Size | 94.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bea787e483809b1d944ef28a3068816d71e6e0228fdb638733160e0405f2cdf5
|
|
BLAKE2b-256 checksum How to use checksums |
9d828fdca15e9b882aef423154eecf670d9978ee5cf9031ac6bf4e7ca8bbfb2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / oidcauthlib-3.1.0-py3-none-any.whl
| Download URL | oidcauthlib-3.1.0-py3-none-any.whl |
|---|---|
| Size | 123.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc538d07597446509d8d75f10c3eaee4d5ff805a674d03f7ef47ea987fe2f180
|
|
BLAKE2b-256 checksum How to use checksums |
806a649ae41c7afa120554ce5536883e6bce76c7d8959d07d802bcc9259cbd98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for oidcauthlib 3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.