UToken - Secure tokens
UToken (or Unhandleable Token) is a library designed to generate secure tokens with a guarantee of integrity for any type of project. With this project you can add payload and token lifetime.
To install UToken, use the pip package manager:
pip install utokeniz
How to use
Here's a short tutorial on how to use UToken in a simple way.
Creating a token
Let's start by creating a token, see the code below:
from utoken import encode
# defining our key
KEY = 'secret-key'
# encoding
my_token = encode({'message': 'Hello World!'}, KEY)
print(my_token)
First we pass as a parameter to utoken.encode() the payload of the token, which must be a dictionary, then we pass the key that will be used to encode the token. After that we have our token in a string returned by the function.
Define expiration time
We can add the token expiration time using the expires_in argument of the utoken.encode function. After the maximum time is reached the ExpiredTokenError exception will be thrown. In the example below, the token will expire in 5 minutes:
from utoken import encode
from datetime import timedelta
token = encode({'name': 'Maria'}, 'secret-key', expires_in=timedelta(minutes=5))
Decoding a token
Now, let's decode a token. See the code below:
import utoken
from datetime import timedelta
# defining our key
KEY = 'secret-key'
# create a token
token = utoken.encode({'name': 'Maria'}, KEY, expires_in=timedelta(minutes=5))
# decode a token
payload = utoken.decode(token, KEY)
print(payload)
Ready! Our token has been decoded. In utoken.decode() we pass as a parameter the token and the key used in the encoding, simple.
License
Copyright © 2023 Jaedson Silva
BSD-3-Clause License
This project uses the BSD-3-Clause license. Please see the license file to more informations.
Metadata
Release files for utokeniz 2.0.1
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 |
|---|---|---|---|---|
| utokeniz-2.0.1.tar.gz | 4.9 kB | Without provenance | Details for utokeniz-2.0.1.tar.gz |
Release files / utokeniz-2.0.1.tar.gz
| Download URL | utokeniz-2.0.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d36647eadb8e3bc5317037ed21208040d4907eb6e331cd9fd100614941395c5
|
|
BLAKE2b-256 checksum How to use checksums |
2d86bbb75e1ca9561db6fe88fd0d7e47a001dfd39b611181ccd8ff283d07271c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.14 CPython/3.10.6
|
Security for utokeniz 2.0.1
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.