Short lived tokens v0.1.1
Project description
Short Lived Tokens - Read Me
A short lived token: built over RSA encryption-decryption (but can be extended) and UNIX timestamp working as a salt to build a very short-lived, practically single time use token. Token expiry can be set as small as 100 milliseconds but suggested to have a practical value of 2 to 5 seconds over networked RPC on public cloud.
Quick Setup
Use pip install short_lived_tokens
to install the library.
Usage
Here's a simple example to get you started.
import os
import base64
from short_lived_tokens.endec.time_utils import get_timestamp_ms
import time
from short_lived_tokens.endec import RSAEndecEngine
from short_lived_tokens.token import Token
start_profile = time.time_ns()
TOKEN_LIFE_MS = 100
engine = RSAEndecEngine(token_life_ms=TOKEN_LIFE_MS)
if not os.path.exists('priv.pem') or not os.path.exists('pub.pem'):
pubkey, privkey = engine.generate_keypair(4096)
engine.save_key('priv.pem', privkey)
engine.save_key('pub.pem', pubkey)
engine.load_key('priv.pem', set_priv=True)
encrypted_token = engine.encrypt("Hello")
print(encrypted_token.hex())
b64_auth_token = base64.b64encode(encrypted_token)
print(b64_auth_token)
token = Token(engine, b64_auth_token)
print(token.is_valid())
print('Sleeping...')
time.sleep(0.002)
print(token.is_valid(reset=True))
time.sleep(0.1)
print(token.is_valid(reset=True))
time.sleep(1)
print(token.is_valid(reset=True))
end_profile = time.time_ns()
print(f"Elapsed: {(end_profile - start_profile)/10**6} ms")
TODOs
Django Wrapper for easy installation and usage with Django Framework.
Contributers
Tushar Srivastava <tusharsrivastava@friedbotstudio.com>
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for short_lived_tokens-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd605594b15de203f8a6372f4d7345f96128aeb4fb0ec030639c8840a0dc22ba |
|
MD5 | a058aa3be35b27fb09700f05ac8f16a5 |
|
BLAKE2b-256 | 3200beb6fc370946504e3c224a9699ade1f6f906f2741252fa271d4ce7c6c5ff |