Created
March 19, 2012 17:00
-
-
Save michaelhelmick/2119276 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_authentication_tokens(self): | |
""" | |
get_auth_url(self) | |
Returns an authorization URL for a user to hit. | |
""" | |
callback_url = self.callback_url or 'oob' | |
request_args = {} | |
method = 'get' | |
if OAUTH_LIB_SUPPORTS_CALLBACK: | |
print 'oauth callback supported' | |
request_args['oauth_callback'] = callback_url | |
else: | |
print 'oauth callback NOT supported!!!' | |
request_args['body'] = urllib.urlencode({'oauth_callback': callback_url}) | |
method = 'post' | |
func = getattr(self.client, method) | |
response = func(self.request_token_url, data=request_args) | |
#response = self.client.get(self.request_token_url, data=request_args) | |
if response.status_code != 200: | |
raise TwythonAuthError("Seems something couldn't be verified with your OAuth junk. Error: %s, Message: %s" % (response.status_code, response.content)) | |
request_tokens = dict(parse_qsl(response.content)) | |
if not request_tokens: | |
raise TwythonError('Unable to decode request tokens.') | |
oauth_callback_confirmed = request_tokens.get('oauth_callback_confirmed') == 'true' | |
if not OAUTH_LIB_SUPPORTS_CALLBACK and callback_url != 'oob' and oauth_callback_confirmed: | |
import warnings | |
warnings.warn("oauth2 library doesn't support OAuth 1.0a type callback, but remote requires it") | |
oauth_callback_confirmed = False | |
auth_url_params = { | |
'oauth_token': request_tokens['oauth_token'], | |
} | |
# Use old-style callback argument | |
if OAUTH_CALLBACK_IN_URL or (callback_url != 'oob' and not oauth_callback_confirmed): | |
auth_url_params['oauth_callback'] = callback_url | |
request_tokens['auth_url'] = self.authenticate_url + '?' + urllib.urlencode(auth_url_params) | |
return request_tokens |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment