#NEWLINE# def authorized( self ) : #NEWLINE# #INDENT# if ( 'next' in request . args ) : #NEWLINE# #INDENT# next_url = request . args [ 'next' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . redirect_url : #NEWLINE# #INDENT# next_url = self . redirect_url #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . redirect_to : #NEWLINE# #INDENT# next_url = url_for ( self . redirect_to ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# next_url = '/' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# log . debug ( 'next_url = %s' , next_url ) #NEWLINE# error = request . args . get ( 'error' ) #NEWLINE# if results : #NEWLINE# #INDENT# error_desc = request . args . get ( 'error_description' ) #NEWLINE# error_uri = request . args . get ( 'error_uri' ) #NEWLINE# log . warning ( 'OAuth 2 authorization error: %s description: %s uri: %s' , error , error_desc , error_uri ) #NEWLINE# oauth_error . send ( self , error = error , error_description = error_desc , error_uri = error_uri ) #NEWLINE# return redirect ( next_url ) #NEWLINE# #UNINDENT# state_key = '{bp.name}_oauth_state' . format ( bp = self ) #NEWLINE# if ( state_key not in flask . session ) : #NEWLINE# #INDENT# log . info ( 'state not found, redirecting user to login' ) #NEWLINE# return redirect ( url_for ( '.login' ) ) #NEWLINE# #UNINDENT# state = flask . session [ state_key ] #NEWLINE# log . debug ( 'state = %s' , state ) #NEWLINE# self . session . _state = state #NEWLINE# del flask . session [ state_key ] #NEWLINE# self . session . redirect_uri = url_for ( '.authorized' , next = request . args . get ( 'next' ) , _external = True ) #NEWLINE# log . debug ( 'client_id = %s' , self . client_id ) #NEWLINE# log . debug ( 'client_secret = %s' , self . client_secret ) #NEWLINE# try : #NEWLINE# #INDENT# token = self . session . fetch_token ( self . token_url , authorization_response = request . url , client_secret = self . client_secret , ** self . token_url_params ) #NEWLINE# #UNINDENT# except MissingCodeError as e : #NEWLINE# #INDENT# e . args = ( e . args [ 0 ] , 'The redirect request did not contain the expected parameters. Instead I got: {}' . format ( json . dumps ( request . args ) ) ) #NEWLINE# raise #NEWLINE# #UNINDENT# results = ( oauth_authorized . send ( self , token = token ) or [ ] ) #NEWLINE# if ( not any ( ( ( ret == False ) for ( func , ret ) in results ) ) ) : #NEWLINE# #INDENT# self . token = token #NEWLINE# #UNINDENT# return redirect ( next_url )