#NEWLINE# def do_oauth2_authorization( self , session ) : #NEWLINE# #INDENT# ' OAuth2. More info: https://vk.com/dev/auth_mobile\n        ' #NEWLINE# logger . info ( 'Doing oauth2' ) #NEWLINE# auth_data = { #NEWLINE# #INDENT# 'client_id' : self . app_id , #NEWLINE# 'display' : 'mobile' , #NEWLINE# 'response_type' : 'token' , #NEWLINE# 'scope' : self . scope , #NEWLINE# 'v' : self . api_version , #NEWLINE# #UNINDENT# } #NEWLINE# response = session . post ( url = self . AUTHORIZE_URL , data = stringify_values ( auth_data ) ) #NEWLINE# url_query_params = parse_url_query_params ( response . url ) #NEWLINE# if ( 'expires_in' in url_query_params ) : #NEWLINE# #INDENT# logger . info ( ( 'Token will be expired in %s sec.' % url_query_params [ 'expires_in' ] ) ) #NEWLINE# #UNINDENT# if ( 'access_token' in url_query_params ) : #NEWLINE# #INDENT# return url_query_params #NEWLINE# #UNINDENT# logger . info ( 'Getting permissions' ) #NEWLINE# action_url = parse_form_action_url ( response . text ) #NEWLINE# logger . debug ( 'Response form action: %s' , action_url ) #NEWLINE# if action_url : #NEWLINE# #INDENT# response = session . get ( action_url ) #NEWLINE# url_query_params = parse_url_query_params ( response . url ) #NEWLINE# return url_query_params #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# response_json = response . json ( ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# error_message = 'OAuth2 grant access error' #NEWLINE# logger . error ( response . text ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# error_message = 'VK error: [{}] {}' . format ( response_json [ 'error' ] , response_json [ 'error_description' ] ) #NEWLINE# #UNINDENT# logger . error ( 'Permissions obtained' ) #NEWLINE# raise VkAuthError ( error_message )