def __init__(self, *args, **kwargs): self.oauth_server = oauth.Server(MockOAuthDataStore()) self.oauth_server.add_signature_method( oauth.SignatureMethod_PLAINTEXT()) self.oauth_server.add_signature_method( oauth.SignatureMethod_HMAC_SHA1()) BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
def verify_oauth_request(request, oauth_request, consumer, token=None): """ Helper function to verify requests. """ from .store import get_store_singleton # Check nonce if not get_store_singleton().check_nonce(request, oauth_request, oauth_request['oauth_nonce'], oauth_request['oauth_timestamp']): return False # Verify request try: oauth_server = oauth.Server() oauth_server.add_signature_method(oauth.SignatureMethod_HMAC_SHA1()) oauth_server.add_signature_method(oauth.SignatureMethod_PLAINTEXT()) # Ensure the passed keys and secrets are ascii, or HMAC will complain. consumer = oauth.Consumer(consumer.key.encode('ascii', 'ignore'), consumer.secret.encode('ascii', 'ignore')) if token is not None: token = oauth.Token(token.key.encode('ascii', 'ignore'), token.secret.encode('ascii', 'ignore')) oauth_server.verify_request(oauth_request, consumer, token) except oauth.Error as err: return False return True
def initialize_server_request(request): """Shortcut for initialization.""" oauth_request = get_oauth_request(request) if oauth_request: oauth_server = oauth.Server() if 'plaintext' in OAUTH_SIGNATURE_METHODS: oauth_server.add_signature_method( oauth.SignatureMethod_PLAINTEXT()) if 'hmac-sha1' in OAUTH_SIGNATURE_METHODS: oauth_server.add_signature_method( oauth.SignatureMethod_HMAC_SHA1()) else: oauth_server = None return oauth_server, oauth_request
def __init__(self): self._server = oauth.Server() self._server.add_signature_method(oauth.SignatureMethod_HMAC_SHA1()) self._server.add_signature_method(oauth.SignatureMethod_PLAINTEXT())