Example #1
0
class AuthorizeAgent(AgentThreadedBase):

    CALLBACK_URL = "oob"
    
    REQUEST_TOKEN="oauth_request_token"
    ACCESS_TOKEN_KEY="oauth_access_token_key"
    ACCESS_TOKEN_SECRET="oauth_access_token_secret"
    VERIFICATION_CODE="oauth_verification_code"
    
    def __init__(self, app_name, server, port, consumer_key, consumer_secret, base):
        """
        @param interval: interval in seconds
        """
        AgentThreadedBase.__init__(self)
        self.server=server
        self.port=port
        self.base=base
        
        self.consumer_key=consumer_key
        self.consumer_secret=consumer_secret
        self.app_name=app_name
        self.client=OauthClient(server, port, base)
        self.consumer=None
        self.signature_method_plaintext = oauth.OAuthSignatureMethod_PLAINTEXT()
        self.signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
        self.token=None
        self.sm=StateManager(self.app_name)

    def h_start_authorize(self, *_):
        try:
            self.token=None
            self.consumer = oauth.OAuthConsumer(self.consumer_key, self.consumer_secret)            
            oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, 
                                                                       callback=self.CALLBACK_URL, 
                                                                       http_url=self.client.request_token_url)
            oauth_request.sign_request(self.signature_method_hmac_sha1, self.consumer, None)
            self.token = self.client.fetch_request_token(oauth_request)
            oauth_request = oauth.OAuthRequest.from_token_and_callback(token=self.token, 
                                                                       http_url=self.client.authorize_token_url)
            url= oauth_request.to_url()
            self.sm.save(self.REQUEST_TOKEN, self.token)
        except Exception,e:
            self.pub("error_requesttoken", e)
            self.pub("log", "warning", "Authorization: 'RequestToken' failed: "+str(e))
            return

        self.pub("log", "getting authorization from url: "+url)
        try:        
            webbrowser.open(url)
            print url
        except Exception,e:
            self.pub("log", "error", "Opening url(%s)" % url)
Example #2
0
 def __init__(self, app_name, server, port, consumer_key, consumer_secret, base):
     """
     @param interval: interval in seconds
     """
     AgentThreadedBase.__init__(self)
     self.server=server
     self.port=port
     self.base=base
     
     self.consumer_key=consumer_key
     self.consumer_secret=consumer_secret
     self.app_name=app_name
     self.client=OauthClient(server, port, base)
     self.consumer=None
     self.signature_method_plaintext = oauth.OAuthSignatureMethod_PLAINTEXT()
     self.signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
     self.token=None
     self.sm=StateManager(self.app_name)