#NEWLINE# def validate_token( token_in_headers , token_in_query_params ) : #NEWLINE# #INDENT# '\n    Validate the provided authentication token.\n\n    :param token_in_headers: Authentication token provided via headers.\n    :type token_in_headers: ``str``\n\n    :param token_in_query_params: Authentication token provided via query params.\n    :type token_in_query_params: ``str``\n\n    :return: TokenDB object on success.\n    :rtype: :class:`.TokenDB`\n    ' #NEWLINE# if ( ( not token_in_headers ) and ( not token_in_query_params ) ) : #NEWLINE# #INDENT# LOG . audit ( 'Token is not found in header or query parameters.' ) #NEWLINE# raise exceptions . TokenNotProvidedError ( 'Token is not provided.' ) #NEWLINE# #UNINDENT# if token_in_headers : #NEWLINE# #INDENT# LOG . audit ( 'Token provided in headers' ) #NEWLINE# #UNINDENT# if token_in_headers : #NEWLINE# #INDENT# LOG . audit ( 'Token provided in query parameters' ) #NEWLINE# #UNINDENT# token_string = ( token_in_headers or token_in_query_params ) #NEWLINE# token = Token . get ( token_string ) #NEWLINE# if ( token . expiry <= date_utils . get_datetime_utc_now ( ) ) : #NEWLINE# #INDENT# LOG . audit ( ( 'Token with id "%s" has expired.' % token . id ) ) #NEWLINE# raise exceptions . TokenExpiredError ( 'Token has expired.' ) #NEWLINE# #UNINDENT# LOG . audit ( ( 'Token with id "%s" is validated.' % token . id ) ) #NEWLINE# return token