#NEWLINE# def validate_token_request( self , request ) : #NEWLINE# #INDENT# request . _params . setdefault ( 'backend' , None ) #NEWLINE# request . _params . setdefault ( 'client_secret' , None ) #NEWLINE# if ( request . grant_type != 'convert_token' ) : #NEWLINE# #INDENT# raise errors . UnsupportedGrantTypeError ( request = request ) #NEWLINE# #UNINDENT# if ( request . token is None ) : #NEWLINE# #INDENT# raise errors . InvalidRequestError ( description = 'Missing token parameter.' , request = request ) #NEWLINE# #UNINDENT# if ( request . backend is None ) : #NEWLINE# #INDENT# raise errors . InvalidRequestError ( description = 'Missing backend parameter.' , request = request ) #NEWLINE# #UNINDENT# if ( not request . client_id ) : #NEWLINE# #INDENT# raise errors . MissingClientIdError ( request = request ) #NEWLINE# #UNINDENT# if ( not self . request_validator . validate_client_id ( request . client_id , request ) ) : #NEWLINE# #INDENT# raise errors . InvalidClientIdError ( request = request ) #NEWLINE# #UNINDENT# if self . request_validator . client_authentication_required ( request ) : #NEWLINE# #INDENT# log . debug ( 'Authenticating client, %r.' , request ) #NEWLINE# if ( not self . request_validator . authenticate_client ( request ) ) : #NEWLINE# #INDENT# log . debug ( 'Invalid client (%r), denying access.' , request ) #NEWLINE# raise errors . InvalidClientError ( request = request ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not self . request_validator . authenticate_client_id ( request . client_id , request ) ) : #NEWLINE# #INDENT# log . debug ( 'Client authentication failed, %r.' , request ) #NEWLINE# raise errors . InvalidClientError ( request = request ) #NEWLINE# #UNINDENT# #UNINDENT# request . grant_type = 'refresh_token' #NEWLINE# self . validate_grant_type ( request ) #NEWLINE# self . validate_scopes ( request ) #NEWLINE# strategy = load_strategy ( request = request . django_request ) #NEWLINE# try : #NEWLINE# #INDENT# backend = load_backend ( strategy , request . backend , reverse ( ( NAMESPACE + ':complete' ) , args = ( request . backend , ) ) ) #NEWLINE# #UNINDENT# except MissingBackend : #NEWLINE# #INDENT# raise errors . InvalidRequestError ( description = 'Invalid backend parameter.' , request = request ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# user = backend . do_auth ( access_token = request . token ) #NEWLINE# #UNINDENT# except requests . HTTPError as e : #NEWLINE# #INDENT# raise errors . InvalidRequestError ( description = 'Backend responded with HTTP{0}: {1}.' . format ( e . response . status_code , e . response . text ) , request = request ) #NEWLINE# #UNINDENT# if ( not user ) : #NEWLINE# #INDENT# raise errors . InvalidGrantError ( 'Invalid credentials given.' , request = request ) #NEWLINE# #UNINDENT# request . user = user #NEWLINE# log . debug ( 'Authorizing access to user %r.' , request . user )