provide a default for the oauth result urls

This commit is contained in:
mixedpuppy 2010-10-01 14:22:01 -07:00
Родитель f5982a5a4a
Коммит 01dcc9bdb6
5 изменённых файлов: 19 добавлений и 13 удалений

Просмотреть файл

@ -14,6 +14,9 @@ test_shortener = no
bitly.userid = linkdrop
bitly.key = R_9d8dc7f30887c45eb7b3719d71251006
oauth_failure = /auth.html#oauth_failure
oauth_success = /auth.html#oauth_success
oauth.twitter.com.consumer_key = Z2EEt5NCkwkfPCMhUq5Ew
oauth.twitter.com.consumer_secret = EWQhLT1l4vn4ezehtKwcHPUF4XLaVs1zZrqMY5YjtE
oauth.twitter.com.request = https://twitter.com/oauth/request_token

Просмотреть файл

@ -15,6 +15,9 @@ test_shortener = yes
bitly.userid = FILL_ME_IN
bitly.key = FILL_ME_IN
oauth_failure = /auth.html#oauth_failure
oauth_success = /auth.html#oauth_success
# Register with twitter at http://dev.twitter.com/apps/new
oauth.twitter.com.consumer_key = FILL_ME_IN
oauth.twitter.com.consumer_secret = FILL_ME_IN

Просмотреть файл

@ -109,6 +109,6 @@ OAuth authorization api.
import traceback
traceback.print_exc()
err = urllib.urlencode([('error',str(e))])
url = session['end_point_auth_failure'].split('#')
url = session.get('end_point_auth_failure',config.get('oauth_failure')).split('#')
return redirect('%s?%s#%s' % (url[0], err, url[1]))
return redirect(session['end_point_success'])
return redirect(session.get('end_point_success', config.get('oauth_success')))

Просмотреть файл

@ -38,8 +38,8 @@ class OAuth1():
self.sigmethod = oauth.SignatureMethod_HMAC_SHA1()
def request_access(self):
session['end_point_success'] = request.POST['end_point_success']
session['end_point_auth_failure'] = request.POST['end_point_auth_failure']
session['end_point_success'] = request.POST.get('end_point_success', self.config.get('oauth_success'))
session['end_point_auth_failure'] = request.POST.get('end_point_auth_failure', self.config.get('oauth_failure'))
force_login = request.POST.get('force_login') and True
# Create the consumer and client, make the request
@ -76,13 +76,13 @@ class OAuth1():
request_token = oauth.Token.from_string(session['token'])
verifier = request.GET.get('oauth_verifier')
if not verifier:
redirect(session['end_point_auth_failure'])
redirect(session.get('end_point_auth_failure',self.config.get('oauth_failure')))
request_token.set_verifier(verifier)
client = oauth.Client(self.consumer, request_token)
resp, content = client.request(self.access_token_url, "POST")
if resp['status'] != '200':
redirect(session['end_point_auth_failure'])
redirect(session.get('end_point_auth_failure',self.config.get('oauth_failure')))
access_token = dict(urlparse.parse_qsl(content))
return self._get_credentials(access_token)
@ -102,8 +102,8 @@ class OAuth2():
self.scope = self.config.get('scope', None)
def request_access(self):
session['end_point_success'] = request.POST['end_point_success']
session['end_point_auth_failure'] = request.POST['end_point_auth_failure']
session['end_point_success'] = request.POST.get('end_point_success', self.config.get('oauth_success'))
session['end_point_auth_failure'] = request.POST.get('end_point_auth_failure', self.config.get('oauth_failure'))
session.save()
return_to = url(controller='account', action="verify",

Просмотреть файл

@ -223,15 +223,15 @@ class OpenIDResponder():
log.debug('Handling OpenID login')
# Load default parameters that all Auth Responders take
session['end_point_success'] = request.POST['end_point_success']
session['end_point_auth_failure'] = request.POST['end_point_auth_failure']
session['end_point_success'] = request.POST.get('end_point_success', self.config.get('oauth_success'))
fail_uri = session['end_point_auth_failure'] = request.POST.get('end_point_auth_failure', self.config.get('oauth_failure'))
openid_url = request.POST.get('openid_identifier')
# Let inherited consumers alter the openid identifier if desired
openid_url = self._lookup_identifier(openid_url)
if not openid_url or (self.endpoint_regex and not re.match(self.endpoint_regex, end_point)):
return redirect(session['end_point_auth_failure'])
return redirect(fail_uri)
openid_session = {}
oidconsumer = consumer.Consumer(openid_session, self.openid_store)
@ -239,10 +239,10 @@ class OpenIDResponder():
try:
authrequest = oidconsumer.begin(openid_url)
except consumer.DiscoveryFailure:
return redirect(session['end_point_auth_failure'])
return redirect(fail_uri)
if authrequest is None:
return redirect(session['end_point_auth_failure'])
return redirect(fail_uri)
# Update the authrequest
self._update_authrequest(authrequest)