<s> import oauth2 as oauth <EOL> from django . http import HttpResponse <EOL> def get_oauth_request ( request ) : <EOL> """<STR_LIT>""" <EOL> headers = { } <EOL> if '<STR_LIT>' in request . META : <EOL> headers [ '<STR_LIT>' ] = request . META [ '<STR_LIT>' ] <EOL> return oauth . Request . from_request ( request . method , request . build_absolute_uri ( request . path ) , headers , <EOL> dict ( request . REQUEST ) ) <EOL> def verify_oauth_request ( request , oauth_request , consumer , token = None ) : <EOL> """<STR_LIT>""" <EOL> from treeio . core . api . auth . store import store <EOL> if not store . check_nonce ( request , oauth_request , oauth_request [ '<STR_LIT>' ] ) : <EOL> return False <EOL> try : <EOL> oauth_server = oauth . Server ( ) <EOL> oauth_server . add_signature_method ( oauth . SignatureMethod_HMAC_SHA1 ( ) ) <EOL> oauth_server . add_signature_method ( oauth . SignatureMethod_PLAINTEXT ( ) ) <EOL> consumer = oauth . Consumer ( consumer . key . encode ( <EOL> '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) , consumer . secret . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> if token is not None : <EOL> token = oauth . Token ( <EOL> token . key . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) , token . secret . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> oauth_server . verify_request ( oauth_request , consumer , token ) <EOL> except oauth . Error : <EOL> return False <EOL> return True <EOL> def require_params ( oauth_request , parameters = None ) : <EOL> """<STR_LIT>""" <EOL> if parameters is None : <EOL> parameters = [ ] <EOL> params = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> params . extend ( parameters ) <EOL> missing = list ( <EOL> param for param in params if not oauth_request or param not in oauth_request ) <EOL> if missing : <EOL> response = HttpResponse ( <EOL> '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( missing ) ) ) <EOL> response . status_code = <NUM_LIT> <EOL> return response <EOL> return None </s>
