a method to extract and validate jwt session token from request headers

    :param request_headers: dictionary with header fields from request
    :param session_header: string with name of session token header key
    :param secret_key: string with secret key to json web token encryption
    :return: dictionary with request details with session details or error coding

def extract_session_details(request_headers, session_header, secret_key):

    '''
        a method to extract and validate jwt session token from request headers

    :param request_headers: dictionary with header fields from request
    :param session_header: string with name of session token header key
    :param secret_key: string with secret key to json web token encryption
    :return: dictionary with request details with session details or error coding
    '''

    session_details = {
        'error': '',
        'code': 200,
        'session': {}
    }

    if not session_header in request_headers.keys():
        session_details['error'] = '%s is missing.' % session_header
        session_details['code'] = 400
    else:
        import jwt
        session_token = request_headers[session_header]
        try:
            session_details['session'] = jwt.decode(session_token, secret_key)
        except jwt.DecodeError as err:
            session_details['error'] = 'Session token decoding error.'
            session_details['code'] = 400
        except jwt.ExpiredSignatureError as err:
            session_details['error'] = 'Session token has expired.'
            session_details['code'] = 400
        except Exception:
            session_details['error'] = 'Session token is invalid.'
            session_details['code'] = 400

    return session_details