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.0.1.tar.gz (12.1 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.0.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psp_auth-1.0.1.tar.gz
  • Upload date:
  • Size: 12.1 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.0.1.tar.gz
Algorithm Hash digest
SHA256 caa738643228f4a441b46810c84afbc4151af3037bb2c5aafdc6f8a2fed854af
MD5 00f50600b470a03618f11c4d913963ae
BLAKE2b-256 306c893815f27f735f32e5223c2abb773da375f11865f1be682d16a8cf273497

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: psp_auth-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fcc76c54087a9818c7f817ee1d8671b401157232cb612f7f313f88ab0459d3ed
MD5 70fde1b85746ad8c1f900c8e14d91500
BLAKE2b-256 62f168ceb791bc87a84dead2f027006243370ee1a0dc90165478ee7ae26bd2c6

See more details on using hashes here.

Provenance

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