Started implementing PIN for OAuth... entry doesn't show up in popup
This commit is contained in:
parent
4443d9d12c
commit
716e20a9b2
|
@ -7,6 +7,8 @@ import twitter_pb2
|
||||||
from oauthtwitter import OAuthApi
|
from oauthtwitter import OAuthApi
|
||||||
from urllib2 import HTTPError,URLError
|
from urllib2 import HTTPError,URLError
|
||||||
import avcache
|
import avcache
|
||||||
|
import webbrowser
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
# These are the global constants for the twitter oauth entry for our app
|
# These are the global constants for the twitter oauth entry for our app
|
||||||
CONSUMER_KEY = 'jGu64TPCUtyLZKyWyMJldQ'
|
CONSUMER_KEY = 'jGu64TPCUtyLZKyWyMJldQ'
|
||||||
|
@ -465,15 +467,29 @@ def dms_to_statuses(direct_messages):
|
||||||
return statuses
|
return statuses
|
||||||
|
|
||||||
|
|
||||||
def get_access_token():
|
def get_access_token(window):
|
||||||
auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
|
auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
|
||||||
request_token = auth_api.getRequestToken()
|
request_token = auth_api.getRequestToken()
|
||||||
authorization_url = auth_api.getAuthorizationURL(request_token)
|
authorization_url = auth_api.getAuthorizationURL(request_token)
|
||||||
|
|
||||||
# Get authentication from url... buh?
|
webbrowser.open(authorization_url)
|
||||||
|
|
||||||
print 'debug: authorization_url: ' + authorization_url
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token)
|
auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token)
|
||||||
return auth_api.getAccessToken()
|
|
||||||
|
dialog = gtk.Dialog("Enter PIN", window, gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
|
||||||
|
entry = gtk.Entry()
|
||||||
|
dialog.vbox.pack_start(entry)
|
||||||
|
response = dialog.run()
|
||||||
|
dialog.hide()
|
||||||
|
|
||||||
|
if response == gtk.RESPONSE_OK:
|
||||||
|
pin = entry.get_text()
|
||||||
|
|
||||||
|
try:
|
||||||
|
access_token = auth_api.getAccessToken(pin)
|
||||||
|
except HTTPError:
|
||||||
|
access_token = None
|
||||||
|
|
||||||
|
return access_token
|
||||||
|
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
5
hrafn.py
5
hrafn.py
|
@ -536,7 +536,10 @@ class Hrafn():
|
||||||
|
|
||||||
|
|
||||||
def on_file_add_account(self, widget):
|
def on_file_add_account(self, widget):
|
||||||
token = apithreads.get_access_token()
|
token = apithreads.get_access_token(self.window)
|
||||||
|
if token is None:
|
||||||
|
return
|
||||||
|
|
||||||
api = apithreads.CustomApi(token)
|
api = apithreads.CustomApi(token)
|
||||||
username = api.username
|
username = api.username
|
||||||
|
|
||||||
|
|
|
@ -181,8 +181,11 @@ class OAuthApi(Api):
|
||||||
signin_url = self.getAuthorizationURL(token, url)
|
signin_url = self.getAuthorizationURL(token, url)
|
||||||
return signin_url
|
return signin_url
|
||||||
|
|
||||||
def getAccessToken(self, url=ACCESS_TOKEN_URL):
|
def getAccessToken(self, pin=None, url=ACCESS_TOKEN_URL):
|
||||||
token = self._FetchUrl(url, no_cache=True)
|
params = None
|
||||||
|
if pin:
|
||||||
|
params = {'oauth_verifier': pin}
|
||||||
|
token = self._FetchUrl(url, parameters=params, no_cache=True)
|
||||||
return oauth.OAuthToken.from_string(token)
|
return oauth.OAuthToken.from_string(token)
|
||||||
|
|
||||||
def getRequestToken(self, url=REQUEST_TOKEN_URL):
|
def getRequestToken(self, url=REQUEST_TOKEN_URL):
|
||||||
|
|
Reference in New Issue
Block a user