fastapi-tj-tpauth-jwt
Integrate JWT into FastAPI using TP Servers authentication.
Installation
pip install fastapi-tj-tpauth-jwt
Usage
Basic Example
from datetime import timedelta
from typing import Annotated
from fastapi import FastAPI, Depends
from tj_tpauth import TJTPAuth, TPAuthData
from fastapi_tj_tpauth_jwt.tpauth_jwt import TPAuthJWT
app = FastAPI()
tpauth = TJTPAuth(
host="localhost:8080"
)
tpauth_jwt = TPAuthJWT(
tp_auth=tpauth,
secret_key="<SECRET_KEY>",
refresh_secret_key="<SECRET_KEY>",
access_token_expires_in=timedelta(minutes=60),
refresh_token_expires_in=timedelta(minutes=120),
algorithm='HS256'
)
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.post("/login")
async def login(
login_res: Annotated[
tpauth_jwt.provide_login_handler(), Depends()
]
):
return login_res
@app.post("/refresh")
async def refresh(
refresh_res: Annotated[
tpauth_jwt.provide_refresh_token_handler(), Depends()
]
):
return refresh_res
@app.get("/secret_data")
async def secret_data(
payload: Annotated[
tpauth_jwt.provide_require_jwt(), Depends()
]
):
if not isinstance(payload, TPAuthData):
return payload
payload: TPAuthData
return {
"payload": payload.id,
}
Custom Unauthorized Error Response
def unauthorized_response_provider(tpauth_status: TPAuthStatus):
return {
"error": "Unauthorized",
"status": tpauth_status.error.value
}
tpauth_jwt.unauthorized_response_provider = unauthorized_response_provider
Custom JWT Response
def jwt_provider(access_token: str, refresh_token: str, token_type: str):
return {
"access_token": access_token,
"refresh_token": refresh_token,
"token_type": token_type
}
tpauth_jwt.jwt_response_provider = jwt_provider
License
This library is released under the MIT License.
Contact
If you have any questions or issues, please open an issue on GitHub or email us at duynguyen02.dev@gmail.com.
Metadata
Release files for fastapi-tj-tpauth-jwt 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_tj_tpauth_jwt-1.0.0.tar.gz | 3.9 kB | Without provenance | Details for fastapi_tj_tpauth_jwt-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_tj_tpauth_jwt-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_tj_tpauth_jwt-1.0.0-py3-none-any.whl |
Total release size: 8.8 kB
Release files / fastapi_tj_tpauth_jwt-1.0.0.tar.gz
| Download URL | fastapi_tj_tpauth_jwt-1.0.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01c9b2c678c0517b0f45affcbf884748e310fe662a9f253cede4515d683d397d
|
|
BLAKE2b-256 checksum How to use checksums |
34d7adac3525faa29d16a284390f8d383ef51554fc0af91dcd0c3e403083ab14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic
|
Release files / fastapi_tj_tpauth_jwt-1.0.0-py3-none-any.whl
| Download URL | fastapi_tj_tpauth_jwt-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
418c28e71ae5fc9ca362801e1c3dde2522b85fc112ed78ec2ff22fe96c49a67a
|
|
BLAKE2b-256 checksum How to use checksums |
826b43629f2f82107d6b35339622cf40ee0b0f73eb83606306da076c449fb472
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-41-generic
|
Security for fastapi-tj-tpauth-jwt 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.