Metadata-Version: 2.1
Name: immersa-jwt
Version: 1.0.0
Summary: A library Generate JWT, validate, and extract session info from JWT
Home-page: https://github.com/immersa-co/jwt
Author: Prisdha Dharma
Author-email: prisdha@immersa.co
License: MIT
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Description-Content-Type: text/markdown
Requires-Dist: python-jose

# JWT

An implementation of JSON Web Token.

# Install

```bash
$ 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`

