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-1.1.0.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-1.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psp_auth-1.1.0.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-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0638bcb29730f4b8274d1df96c1da16aa5f0900ada1890d2f6e63314cb92fb3f
MD5 492e55295eb9174f9d8baa7554333338
BLAKE2b-256 6f7e59a10d7b41cad461618bac3ef8dc6076b9537b55ea9b48ac5da63f0c5eff

See more details on using hashes here.

Provenance

The following attestation bundles were made for psp_auth-1.1.0.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-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: psp_auth-1.1.0-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-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 798686c1e031532b15a2a725cdb044aff67e6215a9eaa0b829540fe9c8b06117
MD5 5a355f54c46773581240e3e1b80b9799
BLAKE2b-256 0c8b8ae7a3f04ceb37e01e888953d369e4170a0558f1d680305ee6bf3bb18bb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for psp_auth-1.1.0-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