#NEWLINE# def authorize_handler( self , f ) : #NEWLINE# #INDENT# "Authorization handler decorator.\n\n        This decorator will sort the parameters and headers out, and\n        pre validate everything::\n\n            @app.route('/oauth/authorize', methods=['GET', 'POST'])\n            @oauth.authorize_handler\n            def authorize(*args, **kwargs):\n                if request.method == 'GET':\n                    # render a page for user to confirm the authorization\n                    return render_template('oauthorize.html')\n\n                confirm = request.form.get('confirm', 'no')\n                return confirm == 'yes'\n        " #NEWLINE# @ wraps ( f ) #NEWLINE# def decorated( * args , **kwargs ) : #NEWLINE# #INDENT# server = self . server #NEWLINE# ( uri , http_method , body , headers ) = extract_params ( True ) #NEWLINE# if ( request . method in ( 'GET' , 'HEAD' ) ) : #NEWLINE# #INDENT# redirect_uri = request . query . get ( 'redirect_uri' , self . error_uri ) #NEWLINE# log . debug ( 'Found redirect_uri %s.' , redirect_uri ) #NEWLINE# try : #NEWLINE# #INDENT# ret = server . validate_authorization_request ( uri , http_method , body , headers ) #NEWLINE# ( scopes , credentials ) = ret #NEWLINE# kwargs [ 'scopes' ] = scopes #NEWLINE# kwargs . update ( credentials ) #NEWLINE# #UNINDENT# except oauth2 . FatalClientError as e : #NEWLINE# #INDENT# log . debug ( 'Fatal client error %r' , e ) #NEWLINE# return redirect ( e . in_uri ( self . error_uri ) ) #NEWLINE# #UNINDENT# except oauth2 . OAuth2Error as e : #NEWLINE# #INDENT# log . debug ( 'OAuth2Error: %r' , e ) #NEWLINE# return redirect ( e . in_uri ( redirect_uri ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# redirect_uri = request . params . get ( 'redirect_uri' , self . error_uri ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# rv = f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# except oauth2 . FatalClientError as e : #NEWLINE# #INDENT# log . debug ( 'Fatal client error %r' , e ) #NEWLINE# return redirect ( e . in_uri ( self . error_uri ) ) #NEWLINE# #UNINDENT# except oauth2 . OAuth2Error as e : #NEWLINE# #INDENT# log . debug ( 'OAuth2Error: %r' , e ) #NEWLINE# return redirect ( e . in_uri ( redirect_uri ) ) #NEWLINE# #UNINDENT# if ( not isinstance ( rv , bool ) ) : #NEWLINE# #INDENT# return rv #NEWLINE# #UNINDENT# if ( not rv ) : #NEWLINE# #INDENT# e = oauth2 . AccessDeniedError ( ) #NEWLINE# return redirect ( e . in_uri ( redirect_uri ) ) #NEWLINE# #UNINDENT# return self . confirm_authorization_request ( ) #NEWLINE# #UNINDENT# return decorated