Mercurial > universal-identity-relyer
changeset 8:51dfea268026
removed oauth_callback param
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sat, 12 Jun 2010 20:06:52 -0700 |
parents | c6aef586ab82 |
children | 42fe50c20cc8 |
files | oauth_experiment.py test_twitter_client.py twitter_client.py |
diffstat | 3 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/oauth_experiment.py Sat Jun 12 19:47:49 2010 -0700 +++ b/oauth_experiment.py Sat Jun 12 20:06:52 2010 -0700 @@ -30,12 +30,11 @@ def success_app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) - return ['yay'] + return ['woot %s' % repr(environ['oauth.access_token'])] app = twitter_client.TwitterOauthClientApp( consumer=consumer, oauth=oauth, - oauth_callback='http://localhost:8000/callback', request_tokens=Storage(), success_delegate=success_app )
--- a/test_twitter_client.py Sat Jun 12 19:47:49 2010 -0700 +++ b/test_twitter_client.py Sat Jun 12 20:06:52 2010 -0700 @@ -12,7 +12,7 @@ consumer = 'mock consumer' oauth = Mock('oauth') success_delegate = Mock('success_delegate') - toc = TwitterOauthClientApp(consumer, oauth, 'http://foo.com/oauth_callback', + toc = TwitterOauthClientApp(consumer, oauth, request_tokens, success_delegate) return (consumer, oauth, success_delegate, toc) @@ -37,11 +37,12 @@ ... 'oauth_callback_confirmed=true' ... ) >>> oauth.Client.mock_returns = client - >>> environ = dict(PATH_INFO='/request', QUERY_STRING='') + >>> environ = dict(PATH_INFO='/request', QUERY_STRING='', SERVER_NAME='foo.com', SERVER_PORT='80') + >>> environ['wsgi.url_scheme'] = 'http' >>> toc(environ, Mock('start_response')) Called oauth.Client('mock consumer') Called client.request( - 'https://api.twitter.com/oauth/request_token?oauth_callback=http%3A%2F%2Ffoo.com%2Foauth_callback', + 'https://api.twitter.com/oauth/request_token?oauth_callback=http%3A%2F%2Ffoo.com%2Fcallback', 'GET') Called start_response( '302 Found', @@ -66,8 +67,10 @@ >>> oauth.Token.mock_returns = token >>> environ = dict( ... PATH_INFO='/callback', - ... QUERY_STRING='oauth_token=token&oauth_verifier=verifier' + ... QUERY_STRING='oauth_token=token&oauth_verifier=verifier', + ... SERVER_NAME='foo.com', SERVER_PORT='80' ... ) + >>> environ['wsgi.url_scheme'] = 'http' >>> success_delegate.mock_returns = ['success'] >>> toc(environ, Mock('start_response')) Called oauth.Token('token', 'secret') @@ -75,7 +78,7 @@ Called oauth.Client('mock consumer', <Mock token>) Called client.request('https://api.twitter.com/oauth/access_token', 'POST') Called success_delegate( - {'QUERY_STRING': 'oauth_token=token&oauth_verifier=verifier', 'PATH_INFO': '/callback', 'oauth.access_token': {'oauth_token_secret': 'secret', 'user_id': 'userid', 'oauth_token': 'token', 'screen_name': 'bob'}}, + {'SERVER_NAME': 'foo.com', 'wsgi.url_scheme': 'http', 'PATH_INFO': '/callback', 'SERVER_PORT': '80', 'oauth.access_token': {'oauth_token_secret': 'secret', 'user_id': 'userid', 'oauth_token': 'token', 'screen_name': 'bob'}, 'QUERY_STRING': 'oauth_token=token&oauth_verifier=verifier'}, <Mock start_response>) ['success'] """
--- a/twitter_client.py Sat Jun 12 19:47:49 2010 -0700 +++ b/twitter_client.py Sat Jun 12 20:06:52 2010 -0700 @@ -1,15 +1,15 @@ import json import urlparse import urllib +from wsgiref.util import application_uri class TwitterOauthClientApp(object): request_token_url = 'https://api.twitter.com/oauth/request_token' access_token_url = 'https://api.twitter.com/oauth/access_token' authorize_url = 'https://api.twitter.com/oauth/authorize' - def __init__(self, consumer, oauth, oauth_callback, request_tokens, + def __init__(self, consumer, oauth, request_tokens, success_delegate): - self.oauth_callback = oauth_callback self.oauth = oauth self.consumer = consumer self.success_delegate = success_delegate @@ -24,9 +24,11 @@ # having the user authorize an access token and to sign the request to obtain # said access token. + oauth_callback = '%scallback' % application_uri(environ) + url = '%s?%s' % ( self.request_token_url, - urllib.urlencode({'oauth_callback': self.oauth_callback}) + urllib.urlencode({'oauth_callback': oauth_callback}) ) client = self.oauth.Client(self.consumer) resp, content = client.request(url, "GET")