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 the authentication and authorisation for services. It assumes that you use FastAPI.

Installation

WIP

Usage

First, create the auth:

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

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

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

Then, for an endpoint, you can require that the user has a role:

@app.get("/protected-route")
@auth.require_role("my-role"):
def protected_route(request: Request):
    # (...)

[!IMPORTANT] You NEED to have the request: Request parameter to the function. Additionally, @auth.require_role(...) has to be after @app.get(...).

You can also require that the user has one out of a list of roles: auth.require_any_role(["first-role", "second-role", ...]) You can also require that the user has multiple roles: auth.require_all_roles(["first-role", "second-role", ...])

[!NOTE] There are also similar decorators for checking roles on other resources than your own, for example: auth.require_resource_role("other-service", "their-role").

If you need to access the user's information in an endpoint, you can do:

def protected_route(request: Request):
    token = auth.get_token(request)
    user = token.user()
    # user has information, like `user.id()` and `user.full_name()`.

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.0.tar.gz (12.0 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.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: psp_auth-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 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.0.tar.gz
Algorithm Hash digest
SHA256 3140140cf4ca0e93c422d59396ddd3b71643c12fd96023ff4578a5826b17f09c
MD5 e2486961cda8a3ab512eeef670a6e81a
BLAKE2b-256 04110a11af9f41c92962afe9d6fbfdbaaf30d81bfd72f884d60ecfb91208e573

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: psp_auth-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ba4a22bae3c06ab56fde37b423315f9fdee6cb0743417807ad17131a32f872a
MD5 05c5ce221216e816007dada93b250b5b
BLAKE2b-256 a28cc343dd20b8baa073944783889ffa8b5928d2363f66416f1218bdd55c5f80

See more details on using hashes here.

Provenance

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