#NEWLINE# def require_oauth( self , * realms , **kwargs ) : #NEWLINE# #INDENT# 'Protect resource with specified scopes.' #NEWLINE# def wrapper( f ) : #NEWLINE# #INDENT# @ wraps ( f ) #NEWLINE# def decorated( * args , **kwargs ) : #NEWLINE# #INDENT# for func in self . _before_request_funcs : #NEWLINE# #INDENT# func ( ) #NEWLINE# #UNINDENT# if ( hasattr ( request , 'oauth' ) and request . oauth ) : #NEWLINE# #INDENT# return f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# server = self . server #NEWLINE# ( uri , http_method , body , headers ) = extract_params ( ) #NEWLINE# try : #NEWLINE# #INDENT# ( valid , req ) = server . validate_protected_resource_request ( uri , http_method , body , headers , realms ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . warn ( 'Exception: %r' , e ) #NEWLINE# e . urlencoded = urlencode ( [ ( 'error' , 'unknown' ) ] ) #NEWLINE# e . status_code = 400 #NEWLINE# return _error_response ( e ) #NEWLINE# #UNINDENT# for func in self . _after_request_funcs : #NEWLINE# #INDENT# ( valid , req ) = func ( valid , req ) #NEWLINE# #UNINDENT# if ( not valid ) : #NEWLINE# #INDENT# return abort ( 401 ) #NEWLINE# #UNINDENT# req . user = req . access_token . user #NEWLINE# request . oauth = req #NEWLINE# return f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return decorated #NEWLINE# #UNINDENT# return wrapper