#NEWLINE# def authenticate( self , request ) : #NEWLINE# #INDENT# auth = get_authorization_header ( request ) . split ( ) #NEWLINE# if ( ( not auth ) or ( auth [ 0 ] . lower ( ) != b'token' ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( len ( auth ) == 1 ) : #NEWLINE# #INDENT# msg = _ ( 'Invalid token header. No credentials provided.' ) #NEWLINE# raise exceptions . AuthenticationFailed ( token ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( auth ) > 2 ) : #NEWLINE# #INDENT# msg = _ ( 'Invalid token header. Token string should not contain spaces.' ) #NEWLINE# raise exceptions . AuthenticationFailed ( msg ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# token = auth [ 1 ] . decode ( ) #NEWLINE# #UNINDENT# except UnicodeError : #NEWLINE# #INDENT# msg = _ ( 'Invalid token header. Token string should not contain invalid characters.' ) #NEWLINE# raise exceptions . AuthenticationFailed ( msg ) #NEWLINE# #UNINDENT# return self . authenticate_credentials ( token )