Skip to main content

Create healthy and secure authentication tokens with UTokeniz.

Project description

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 also add the token expiration time using the max-time switch in our dict, after the maximum time is reached the ExpiredTokenError exception will be thrown:

from utoken import encode
from datetime import datetime, timedelta

max_time = datetime.now() + timedelta(minutes=5)
my_token = encode({'message': 'Hello!', 'max-time': max_time}, 'secret-key')

Decoding a token

Now, let's decode a token. See the code below:

from utoken import decode

# defining our key
KEY = 'secret-key'
token = 'eyJtZXNz...'

# decoding
my_decode_token = decode(token, KEY)
print(my_decode_token)

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

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

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

utokeniz-1.1.2.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file utokeniz-1.1.2.tar.gz.

File metadata

  • Download URL: utokeniz-1.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for utokeniz-1.1.2.tar.gz
Algorithm Hash digest
SHA256 6cb391b3a8324c23393d3a9d57ea9f84d02175c3ef66f8f2317663c6f421b326
MD5 2f27aff7ad4d505566b1fda897ff550a
BLAKE2b-256 a6055e5bb402b6c514d970d0cbb8353e9119c1826e5f21ae81c84e6fca4d258d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page