Skip to main content

OAuth2-lib

pypi_version Supported python versions codecov

This project contains a number of classes to perform authentication (AuthN) and authorization (AuthZ) in a FastAPI application.

They can be found in oauth2_lib/fastapi.py. Most notable are:

  • OIDCAuth: AuthN implementation that authenticates a user against a OIDC backend. You can subclass and implement def userinfo() as needed.
    • To use a different AuthN method, subclass the Authentication base class.
  • OIDCUserModel: model of the data returned by OIDCAuth. You can subclass this to rename and/or add fields.
  • OPAAuthorization: AuthZ implementation that authorizes a user's HTTP request against an Open Policy Agent (OPA) instance.
    • To use a different AuthZ method, subclass the Authorization base class.
  • GraphQLOPAAuthorization: AuthZ implementation that authorizes a user's GraphQL query against an Open Policy Agent (OPA) instance.
    • To use a different AuthZ method, subclass the GraphqlAuthorization base class.
  • OPAResult: model of the data returned by OPAAuthorization and GraphQLOPAAuthorization.

The orchestrator-core documentation has a section on Authentication and Authorization that describes how to use/override these classes.

Upgrading to 3.0.0

3.0.0 replaces httpx with httpx2. The client passed to OIDCAuth.userinfo(), OIDCAuth.check_openid_config() and OPAMixin.get_decision() is now an httpx2.AsyncClient.

The annotation only affects type checking, but any value you pass back into that client must come from httpx2 too — an httpx.BasicAuth, Timeout or Limits raises TypeError at runtime:

# Before
from httpx import AsyncClient, BasicAuth


class MyOIDCAuth(OIDCAuth):
    async def userinfo(self, async_request: AsyncClient, token: str) -> OIDCUserModel:
        response = await async_request.post(url, auth=BasicAuth(id, secret))
        return OIDCUserModel(response.json())


# After
from httpx2 import AsyncClient


class MyOIDCAuth(OIDCAuth):
    async def userinfo(self, async_request: AsyncClient, token: str) -> OIDCUserModel:
        response = await async_request.post(url, auth=(id, secret))
        return OIDCUserModel(response.json())

A plain (id, secret) tuple is accepted by both stacks, so that part can land before you upgrade.

The httpx[http2] extra is gone as well; the library only ever made HTTP/1.1 requests, so h2 is no longer installed transitively. If you relied on oauth2-lib to pull httpx into your environment, declare it yourself.

Installation

To install the package from PyPI:

pip install oauth2-lib

Development

Virtual Environment

Steps to setup a virtual environment.

Install uv and create the development environment:

uv sync --locked --group test --group dev

Run project commands through that environment with uv run, for example:

uv run pytest

Unit tests

Run the unit tests through the uv-managed environment:

uv run pytest

Pre-commit

This project uses prek, a fast drop-in replacement for pre-commit, to automatically run a number of checks before making a git commit. The same checks will be performed in the CI pipeline so this can save you some time.

prek is part of the dev dependency group, so it is available after uv sync. Go into the project root and enable it:

uv run prek install

This should output prek installed at .git/hooks/pre-commit. The next time you run git commit the hooks will validate your changes. To run the hooks manually on all files, use uv run prek run --all-files.

Set the package version

When a release version has been assigned, update the package metadata on a clean branch with uv version:

uv version 2.7.1

Specify the full version explicitly so release candidates can be represented, for example uv version 2.7.1rc1.

Supported Python versions

oauth2-lib must support the same python versions as orchestrator-core.

Exceptions to this rule are:

  • A new python version is released: oauth2-lib should support the new version before orchestrator-core does
  • Support for an old python version is dropped: oauth2-lib should drop the python version after orchestrator-core does

Metadata

Release files for oauth2-lib 3.2.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 oauth2-lib 3.2.0
File Size Uploaded Provenance Actions
oauth2_lib-3.2.0.tar.gz 30.1 kB With provenance Details for oauth2_lib-3.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for oauth2-lib 3.2.0
File Interpreter ABI Platform Actions
oauth2_lib-3.2.0-py3-none-any.whl Python 3 none any Details for oauth2_lib-3.2.0-py3-none-any.whl

Total release size: 49.3 kB

Release files / oauth2_lib-3.2.0.tar.gz

Download URL oauth2_lib-3.2.0.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c32ad1b5b41f17d89d684c75e24f61edfbb506f1761d21b1fcfd1e6676dcb57e
BLAKE2b-256 checksum
How to use checksums
a29091f2cd7f04b18749e1b93a4b0456331d3d8c727e64b18f94e4a6454a160b
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 Oct 30, 2026.

Transparency log

Release files / oauth2_lib-3.2.0-py3-none-any.whl

Download URL oauth2_lib-3.2.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc5b0cf6343ca867c5ee6355c528b92179e97dab004a4fa03cc840b8096ebb99
BLAKE2b-256 checksum
How to use checksums
dd8845f87b7cc1e19288d83935e92ad8a895766b3a1d5ef55ea40c1d9114f89a
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 Oct 30, 2026.

Transparency log

Security for oauth2-lib 3.2.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 oauth2_lib-3.2.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 Oct 30, 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.

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files Full provenance

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