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.1.tar.gz (13.6 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.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psp_auth-1.1.1.tar.gz
  • Upload date:
  • Size: 13.6 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.1.tar.gz
Algorithm Hash digest
SHA256 78b435556a80c1ff30f916c450ddbb90ce0893ed548afccbf1117491ce39b4c0
MD5 8d8e48be6c4e2cd7d408d94632c29ec1
BLAKE2b-256 57a11c1f8d644d174dd408824c78b4faed569f07d45c081ceefd37c851360d5e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: psp_auth-1.1.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-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6c7c4e026e70019d2a4c111056c4bb69470111c48d45864592bf5fe2f3a6575
MD5 3508adeeba7e9d922a916e88b626cf3d
BLAKE2b-256 df0b1c6c9f780c948e1d154fa3bfe9dae1dd1ad5f64b01c20ed238e3b42f4843

See more details on using hashes here.

Provenance

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