Skip to main content

A Python library for authentication and authorisation in the PSP platform

Project description

Auth Library for Python

A library that implements authentication and authorisation for services in the Portfolio Solver Platform (PSP).

Installation

You can find the package on PyPI and install it like you would any other PyPI package.

Usage

The Auth class contains the core authentication and authorisation functionality. You create it like this:

auth_core = Auth(AuthConfig("my-service"))

where "my-service" is the service name, corresponding with the resource in the auth provider.

[!IMPORTANT] See Keycloak for how to set up the resource.

FastAPI

This section will describe how to use the FastAPI module. You initialise it like this:

auth = FastAPIAuth(auth_core)

You should then use the FastAPIAuth.add_docs function on your FastAPI app:

app = FastAPI(...)

auth.add_docs(app)

Then, for an endpoint, you can require that the request has scopes:

SCOPES = ["my-scope"]
@app.get("/protected-route", dependencies=[auth.require_scopes(SCOPES)], openapi_extra=auth.scope_docs(SCOPES))
def protected_route():
    # (...)

Note that the openapi_extra part provides the OpenAPI documentation, while the dependencies part provides the functionality.

To get information about the user, you can use auth.user() in a Depends:

@app.get("/protected-route")
def protected_route(user: Annotated[User, Depends(auth.user())]):
    # user has information like their ID, and optionally information like their name
    # (...)

Similarly, you can get access to the token using Annotated[Token, Depends(auth.token())].

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

psp_auth-2.0.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

psp_auth-2.0.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file psp_auth-2.0.1.tar.gz.

File metadata

  • Download URL: psp_auth-2.0.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for psp_auth-2.0.1.tar.gz
Algorithm Hash digest
SHA256 1e8348389b98890fcec8f7a7e2bf4ea0ba01746f33f6e9c95e6b9696fbefc3af
MD5 62277afb1026abb4d59eb8bf6ce13cea
BLAKE2b-256 49a55cdc6f443edb2323e94b36fef8889d01a062535b6c5ad00ab99d52ff7fb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for psp_auth-2.0.1.tar.gz:

Publisher: publish.yml on Portfolio-Solver-Platform/python-auth-lib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file psp_auth-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: psp_auth-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for psp_auth-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ddfaade3cbab08ef884fe5d2666870c6f69e445cbdb6b80be26d0f4545c6ead7
MD5 6889c29a7ae4d5737155a3888f9f4981
BLAKE2b-256 e2493ee60919ee48cc109bfe609e764c8dda65c8cf0c124e7d8c0d9c5938785f

See more details on using hashes here.

Provenance

The following attestation bundles were made for psp_auth-2.0.1-py3-none-any.whl:

Publisher: publish.yml on Portfolio-Solver-Platform/python-auth-lib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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