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
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-2.0.1.tar.gz.
File metadata
- Download URL: psp_auth-2.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e8348389b98890fcec8f7a7e2bf4ea0ba01746f33f6e9c95e6b9696fbefc3af
|
|
| MD5 |
62277afb1026abb4d59eb8bf6ce13cea
|
|
| BLAKE2b-256 |
49a55cdc6f443edb2323e94b36fef8889d01a062535b6c5ad00ab99d52ff7fb3
|
Provenance
The following attestation bundles were made for psp_auth-2.0.1.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-2.0.1.tar.gz -
Subject digest:
1e8348389b98890fcec8f7a7e2bf4ea0ba01746f33f6e9c95e6b9696fbefc3af - Sigstore transparency entry: 1079163356
- Sigstore integration time:
-
Permalink:
Portfolio-Solver-Platform/python-auth-lib@c13d692bb8fc0adc89e877c32f0d6f852261576e -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/Portfolio-Solver-Platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c13d692bb8fc0adc89e877c32f0d6f852261576e -
Trigger Event:
release
-
Statement type:
File details
Details for the file psp_auth-2.0.1-py3-none-any.whl.
File metadata
- Download URL: psp_auth-2.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddfaade3cbab08ef884fe5d2666870c6f69e445cbdb6b80be26d0f4545c6ead7
|
|
| MD5 |
6889c29a7ae4d5737155a3888f9f4981
|
|
| BLAKE2b-256 |
e2493ee60919ee48cc109bfe609e764c8dda65c8cf0c124e7d8c0d9c5938785f
|
Provenance
The following attestation bundles were made for psp_auth-2.0.1-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-2.0.1-py3-none-any.whl -
Subject digest:
ddfaade3cbab08ef884fe5d2666870c6f69e445cbdb6b80be26d0f4545c6ead7 - Sigstore transparency entry: 1079163361
- Sigstore integration time:
-
Permalink:
Portfolio-Solver-Platform/python-auth-lib@c13d692bb8fc0adc89e877c32f0d6f852261576e -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/Portfolio-Solver-Platform
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c13d692bb8fc0adc89e877c32f0d6f852261576e -
Trigger Event:
release
-
Statement type: