Skip to main content

This is the SURF Oauth2 module that interfaces with the oauth2 setup.

Project description

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.

Installation

To install the package from PyPI:

pip install oauth2-lib

Development

Virtual Environment

Steps to setup a virtual environment.

Step 1:

Create and activate a python3 virtualenv.

Step 2:

Install flit to enable you to develop on this repository:

pip install flit

Step 3:

To install all development dependencies:

flit install --deps develop

All steps combined into 1 command:

python -m venv .venv && source .venv/bin/activate && pip install -U pip && pip install flit && flit install --deps develop

Unit tests

Activate the virtualenv and run the unit tests with:

pytest

Pre-commit

This project uses 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.

First ensure you have pre-commit installed. It is recommended to install it outside the virtualenv. On Linux and Mac, pre-commit is available in most package managers. Alternatively you can install it globally with pipx.

Once pre-commit is installed, go into the project root and enable it:

pre-commit install

This should output pre-commit installed at .git/hooks/pre-commit. The next time you run git commit the pre-commit hooks will validate your changes.

Bump version

Depending on the feature type, run bumpversion (patch|minor|major) to increment the version you are working on. For example to update the increment the patch version use

bumpversion patch

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oauth2_lib-2.7.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oauth2_lib-2.7.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file oauth2_lib-2.7.0.tar.gz.

File metadata

  • Download URL: oauth2_lib-2.7.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.33.1

File hashes

Hashes for oauth2_lib-2.7.0.tar.gz
Algorithm Hash digest
SHA256 15d9faff6d6a8ac45c7f2f95739b3e137a328c0a63f6f0a0b3356522d91d7cc8
MD5 05b48654893c47edf65b865a4a396192
BLAKE2b-256 27b4d5822d334e5b87e89d2f2bf0b6281f82c538aa9e6ec1bb2038912c4eca19

See more details on using hashes here.

File details

Details for the file oauth2_lib-2.7.0-py3-none-any.whl.

File metadata

  • Download URL: oauth2_lib-2.7.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.33.1

File hashes

Hashes for oauth2_lib-2.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9384367ce44711128e49d14cf72163f756fe065743f3bef7b0a3f62464c85f8e
MD5 9f93d12eec7aa447a47de4facace320f
BLAKE2b-256 6b683e98a1392950f682f668e95f718873732a0ad3c35c89fe3709333f055e36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page