#NEWLINE# def validate( self , attrs ) : #NEWLINE# #INDENT# view = self . context . get ( 'view' ) #NEWLINE# request = self . _get_request ( ) #NEWLINE# if ( not view ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'View is not defined, pass it as a context variable' ) #NEWLINE# #UNINDENT# adapter_class = getattr ( view , 'adapter_class' , None ) #NEWLINE# if ( not adapter_class ) : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'Define adapter_class in view' ) #NEWLINE# #UNINDENT# adapter = adapter_class ( ) #NEWLINE# app = adapter . get_provider ( ) . get_app ( request ) #NEWLINE# if ( ( 'access_token' in attrs ) and ( 'token_secret' in attrs ) ) : #NEWLINE# #INDENT# access_token = attrs . get ( 'access_token' ) #NEWLINE# token_secret = attrs . get ( 'token_secret' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise serializers . ValidationError ( 'Incorrect input. access_token and token_secret are required.' ) #NEWLINE# #UNINDENT# request . session [ 'oauth_api.twitter.com_access_token' ] = { #NEWLINE# #INDENT# 'oauth_token' : access_token , #NEWLINE# 'oauth_token_secret' : token_secret , #NEWLINE# #UNINDENT# } #NEWLINE# token = SocialToken ( token = access_token , token_secret = token_secret ) #NEWLINE# token . app = app #NEWLINE# try : #NEWLINE# #INDENT# login = self . get_social_login ( adapter , app , token , access_token ) #NEWLINE# complete_social_login ( request , login ) #NEWLINE# #UNINDENT# except OAuthError as e : #NEWLINE# #INDENT# raise serializers . ValidationError ( str ( e ) ) #NEWLINE# #UNINDENT# if ( not login . is_existing ) : #NEWLINE# #INDENT# login . lookup ( ) #NEWLINE# login . save ( request , connect = True ) #NEWLINE# #UNINDENT# attrs [ 'user' ] = login . account . user #NEWLINE# return attrs