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: Requestparameter 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3140140cf4ca0e93c422d59396ddd3b71643c12fd96023ff4578a5826b17f09c
|
|
| MD5 |
e2486961cda8a3ab512eeef670a6e81a
|
|
| BLAKE2b-256 |
04110a11af9f41c92962afe9d6fbfdbaaf30d81bfd72f884d60ecfb91208e573
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psp_auth-1.0.0.tar.gz -
Subject digest:
3140140cf4ca0e93c422d59396ddd3b71643c12fd96023ff4578a5826b17f09c - Sigstore transparency entry: 658859305
- Sigstore integration time:
-
Permalink:
Portfolio-Solver-Platform/python-auth-lib@e16c7ad25544fac35ab8dfb0d1886adc8465ea0a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Portfolio-Solver-Platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e16c7ad25544fac35ab8dfb0d1886adc8465ea0a -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ba4a22bae3c06ab56fde37b423315f9fdee6cb0743417807ad17131a32f872a
|
|
| MD5 |
05c5ce221216e816007dada93b250b5b
|
|
| BLAKE2b-256 |
a28cc343dd20b8baa073944783889ffa8b5928d2363f66416f1218bdd55c5f80
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psp_auth-1.0.0-py3-none-any.whl -
Subject digest:
9ba4a22bae3c06ab56fde37b423315f9fdee6cb0743417807ad17131a32f872a - Sigstore transparency entry: 658859323
- Sigstore integration time:
-
Permalink:
Portfolio-Solver-Platform/python-auth-lib@e16c7ad25544fac35ab8dfb0d1886adc8465ea0a -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Portfolio-Solver-Platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e16c7ad25544fac35ab8dfb0d1886adc8465ea0a -
Trigger Event:
release
-
Statement type: