Skip to main content

A library Generate JWT, validate, and extract session info from JWT

Project description

JWT

An implementation of JSON Web Token.

Install

$ npm install immersa-jwt

Usage

Instantiate JWT object

import os
import jwt

# secret must be 32-character long
secret = os.environ.get("IMMERSA_TOKEN_SECRET")

# expiration denotes the number of seconds the token is valid
expiration = os.environ.get("IMMERSA_TOKEN_EXPIRATION")

# if expiration is ommitted, default is set to 24 hours
JWT = jwt.JWT(secret, expiration)

Given a session which represents dictionary, JWT can be generated by:

session = {
    "id": "61c24785bd77c10012d58199",
    "displayName": "John Smoth",
    "email": "jsmith@immersa.co",
    "admin": True,
}
token = JWT.create-token(session)

The token can then be passed along HTTP request apart of its header. This token can be validated on the server-side by calling:

session = JWT.session(token)

which, in turn, extract the session which was used to the tokken earlier. In case expired or invalid token, JWT.session(token) will raise InvalidTokenError

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

immersa-jwt-1.0.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

immersa_jwt-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file immersa-jwt-1.0.0.tar.gz.

File metadata

  • Download URL: immersa-jwt-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.9

File hashes

Hashes for immersa-jwt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c6da805d34e949b36ece2fab17855628af452134212cd54cb1b94b90db9fb1d9
MD5 6700f5596af1405cc07184268eef45ed
BLAKE2b-256 f1c528fd311dc34a19c0c3055c4f5fd1669cf76d21b2e3eb38d3a3f04e00321a

See more details on using hashes here.

File details

Details for the file immersa_jwt-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: immersa_jwt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.9

File hashes

Hashes for immersa_jwt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f34e0b9d5c38ce00b70b4fc292db1760d13686beb064a5cca48583c6236af90b
MD5 d4c11022a89c4dd0701a5e796ac388f9
BLAKE2b-256 fc4b3e71922df60ef7ba13f1823a743192aeefb7e2a0dec0a5d9cb0e2f903076

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