Skip to main content

Short lived tokens v0.1.2

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 See PYPI.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

short_lived_tokens-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

short_lived_tokens-0.1.2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file short_lived_tokens-0.1.2.tar.gz.

File metadata

  • Download URL: short_lived_tokens-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for short_lived_tokens-0.1.2.tar.gz
Algorithm Hash digest
SHA256 529bdbb647d2667fb2146e6810c3d33e2b1c39a5a1a15570b89109921b4bd17e
MD5 7dcf2c09e1609043297f72beacd3e26a
BLAKE2b-256 3f48fbf3af19df8b5a6f595d2868c16dda1c14687dca24b8a72373d5e38b48b4

See more details on using hashes here.

File details

Details for the file short_lived_tokens-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: short_lived_tokens-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for short_lived_tokens-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79287dc9f27a43b14d52440db55036d92958b683d9677b249a00e24b704c8557
MD5 41bcc57bc5274aec6dc36616fceaf306
BLAKE2b-256 494ec5e7292dc0b05cfad1b003dce4c3d68a3165c39fd0104dd5b86d8031adcb

See more details on using hashes here.

Supported by

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