Skip to content

Commit 401a4fa

Browse files
committed
xauth bug was fixed
1 parent 171f9cc commit 401a4fa

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
python-500px
22
======
3-
A Python client for the 500px API, inspired by tweepy(https://github.com/tweepy/tweepy), python-instagram(https://github.com/Instagram/python-instagram)
3+
A Python client for 500px API, inspired by tweepy(https://github.com/tweepy/tweepy), python-instagram(https://github.com/Instagram/python-instagram)
44

55
Installation
66
----

fivehundredpx/auth.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class OAuthHandler(object):
88

9-
def __init__(self,consumer_key,consumer_secret,callback=None,secure=False):
9+
def __init__(self,consumer_key,consumer_secret,callback=None,secure=True):
1010
self._consumer = oauth.OAuthConsumer(consumer_key,consumer_secret)
1111
self._sigmethod = oauth.OAuthSignatureMethod_HMAC_SHA1()
1212
self.request_token = None
@@ -28,7 +28,7 @@ def set_request_token(self, key, secret):
2828
def set_access_token(self, key, secret):
2929
self.access_token = oauth.OAuthToken(key, secret)
3030

31-
def _get_request_token(self):
31+
def get_request_token(self):
3232
url = self._get_oauth_url('request_token')
3333
request = oauth.OAuthRequest.from_consumer_and_token(self._consumer, http_url=url, callback=self.callback)
3434
request.sign_request(self._sigmethod,self._consumer,None)
@@ -48,7 +48,7 @@ def apply_auth(self,url,method,headers,parameters):
4848

4949
def get_authorization_url(self):
5050
try:
51-
self.request_token = self._get_request_token()
51+
self.request_token = self.get_request_token()
5252
request = oauth.OAuthRequest.from_token_and_callback(
5353
token=self.request_token, http_url=self._get_oauth_url('authorize')
5454
)
@@ -74,6 +74,7 @@ def get_xauth_access_token(self,username,password):
7474
url = self._get_oauth_url('access_token',secure=True)
7575
request = oauth.OAuthRequest.from_consumer_and_token(
7676
oauth_consumer=self._consumer,
77+
token=self.request_token,
7778
http_method='POST',
7879
http_url=url,
7980
parameters={
@@ -82,7 +83,7 @@ def get_xauth_access_token(self,username,password):
8283
'x_auth_password': password
8384
}
8485
)
85-
request.sign_request(self._sigmethod,self._consumer,None)
86+
request.sign_request(self._sigmethod,self._consumer,self.request_token)
8687
response = urlopen(Request(url,data=request.to_postdata()))
8788
self.access_token = oauth.OAuthToken.from_string(response.read())
8889
return self.access_token

tests.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
class AuthTestCase(unittest.TestCase):
2323
def setUp(self):
2424
super(AuthTestCase, self).setUp()
25-
self.consumer_key = CONSUMER_KEY
26-
self.consumer_secret = CONSUMER_SECRET
27-
self.handler = OAuthHandler(self.consumer_key,self.consumer_secret)
25+
self.handler = OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
2826

29-
def _testrequesttoken(self):
27+
def testrequesttoken(self):
3028
headers = {}
3129
self.handler.apply_auth('https://api.500px.com/v1/oauth/request_token', 'POST', headers, { 'oauth_callback' : 'http://localhost' })
3230
conn = httplib.HTTPSConnection('api.500px.com')
@@ -37,7 +35,7 @@ def _testrequesttoken(self):
3735
conn.close()
3836
print "this is your request token:\n%s" % result
3937

40-
def _testauthurlwithverifier(self):
38+
def testauthurlwithverifier(self):
4139
redirect_uri = self.handler.get_authorization_url()
4240
print "Please visit and authorize at:\n%s" % redirect_uri
4341

@@ -49,13 +47,28 @@ def _testauthurlwithverifier(self):
4947
print "this is your access token:\n%s" % token.key
5048
print "this is your access token secret:\n%s" % token.secret
5149

52-
def _testxauth(self):
50+
def testxauth(self):
51+
print "this is your token:\n"
52+
print self.handler.get_request_token()
53+
54+
request_token = raw_input("Input request token (blank to exit): ").strip()
55+
if not request_token:
56+
return
57+
58+
request_token_secret = raw_input("Input request token secret (blank to exit): ").strip()
59+
if not request_token_secret:
60+
return
61+
62+
self.handler.set_request_token(request_token,request_token_secret)
63+
5364
username = raw_input("Input your username (blank to exit): ").strip()
5465
if not username:
5566
return
67+
5668
password = raw_input("Input your password (blank to exit): ").strip()
5769
if not password:
5870
return
71+
5972
token = self.handler.get_xauth_access_token(username,password)
6073

6174
print "this is your access token:\n%s" % token.key

0 commit comments

Comments
 (0)