Last active
December 3, 2017 16:49
-
-
Save mikeywaites/7ca1bf8a2865b49f36caaa0ea1a8c202 to your computer and use it in GitHub Desktop.
api middleware get_client_token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .utils import decode_client_token, get_token_from_request | |
def get_client_token(endpoint): | |
"""Validate the request has a valid JWT token. If the provided api_key and token | |
a valid the JWT will be decoded and stored on g.token for use later on. | |
""" | |
token = get_token_from_request() | |
if not token: | |
payload = {'message': 'Request does not contain token'} | |
endpoint.return_error( | |
401, | |
payload=payload | |
) | |
payload = decode_client_token(g.api_client, token) | |
if not payload: | |
payload = {'message': 'Invalid token'} | |
endpoint.return_error( | |
401, | |
payload=payload, | |
) | |
g.token = payload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment