Middleware REST API Bearer Token Generator
The snippet can be accessed without any authentication.
Authored by
Marvin S. Addison
Edited
#!/usr/bin/env python
import jwt
import os
import sys
import time
# Token validity period in hours
# Set to 0 to produce a token that never expires (not recommended)
VALIDITY_PERIOD=12
if len(sys.argv) < 3:
print "USAGE: ed-id-service /path/to/private.key"
sys.exit(0)
issuer = sys.argv[1]
key_path = sys.argv[2]
with open(key_path, 'r') as f:
key = f.read()
# Create authentication token that is valid for VALIDITY_PERIOD hours
now = int(time.time())
claims = {}
claims['iss'] = 'uusid={0},ou=services,dc=vt,dc=edu'.format(issuer)
claims['iat'] = now
claims['exp'] = now + VALIDITY_PERIOD * 60 * 60
token = jwt.encode(claims, key, algorithm='RS256')
print token
Please register or sign in to comment