The logic for authentication is encapsulated in the thoughts_backend/token_validation.py file. This contains both the generation and the validation of the header.
The following functions generate the Bearer token:
def encode_token(payload, private_key): return jwt.encode(payload, private_key, algorithm='RS256')def generate_token_header(username, private_key): ''' Generate a token header base on the username. Sign using the private key. ''' payload = { 'username': username, 'iat': datetime.utcnow(), 'exp': datetime.utcnow() + timedelta(days=2), } token = encode_token(payload, private_key) token = token.decode('utf8') return f'Bearer {token}'
This generates a JWT payload. It includes username to be used as a custom ...