JWT token creator

A simple json web token creator that wil generate a token based on the secret and payload.

import jwt

def create_token(payload):
    secret = input('Secret: ')
    algorithm = 'HS256'
    
    # Uses jwt module to ecode jwt with payload, secret an alg.
    token = jwt.encode(payload, secret, algorithm=algorithm)
    return token

def json_payload():
    name = input('Name: ')

    # json token payload
    payload = {
        '_id': '67221de57376db047c259cc8', 
        'name': name, 
        'email': '[email protected]', 
        'iat': 1730289242
    }
    return payload

# Json function into variable payload 
payload = json_payload() 

# Call create_token function using payload function
print("\nAdmin token: ", create_token(payload))

Last updated

Was this helpful?