diff options
Diffstat (limited to 'askbot/deps/django_authopenid/util.py')
-rw-r--r-- | askbot/deps/django_authopenid/util.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/askbot/deps/django_authopenid/util.py b/askbot/deps/django_authopenid/util.py index deb9ad27..586136d6 100644 --- a/askbot/deps/django_authopenid/util.py +++ b/askbot/deps/django_authopenid/util.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import cgi +import httplib import urllib import urlparse import functools @@ -182,7 +183,8 @@ def filter_enabled_providers(data): delete_list = list() for provider_key, provider_settings in data.items(): name = provider_settings['name'] - is_enabled = getattr(askbot_settings, 'SIGNIN_' + name.upper() + '_ENABLED') + name_key = name.upper().replace('-', '_') + is_enabled = getattr(askbot_settings, 'SIGNIN_' + name_key + '_ENABLED') if is_enabled == False: delete_list.append(provider_key) @@ -425,7 +427,8 @@ def get_enabled_major_login_providers(): 'resource_endpoint': 'https://graph.facebook.com/', 'icon_media_path': '/jquery-openid/images/facebook.gif', 'get_user_id_function': get_facebook_user_id, - 'response_parser': lambda data: dict(urlparse.parse_qsl(data)) + 'response_parser': lambda data: dict(urlparse.parse_qsl(data)), + 'scope': ['email',], } if askbot_settings.TWITTER_KEY and askbot_settings.TWITTER_SECRET: @@ -500,6 +503,12 @@ def get_enabled_major_login_providers(): 'icon_media_path': '/jquery-openid/images/google.gif', 'openid_endpoint': 'https://www.google.com/accounts/o8/id', } + data['mozilla-persona'] = { + 'name': 'mozilla-persona', + 'display_name': 'Mozilla Persona', + 'type': 'mozilla-persona', + 'icon_media_path': '/jquery-openid/images/mozilla-persona.gif', + } data['yahoo'] = { 'name': 'yahoo', 'display_name': 'Yahoo', @@ -847,7 +856,7 @@ def get_oauth2_starter_url(provider_name, csrf_token): client_id=client_id, redirect_uri=redirect_uri ) - return client.auth_uri(state=csrf_token) + return client.auth_uri(state=csrf_token, scope=params['scope']) def ldap_check_password(username, password): @@ -860,3 +869,26 @@ def ldap_check_password(username, password): except ldap.LDAPError, e: logging.critical(unicode(e)) return False + + +def mozilla_persona_get_email_from_assertion(assertion): + conn = httplib.HTTPSConnection('verifier.login.persona.org') + parsed_url = urlparse.urlparse(askbot_settings.APP_URL) + params = urllib.urlencode({ + 'assertion': assertion, + 'audience': parsed_url.scheme + '://' + parsed_url.netloc + }) + headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'} + conn.request('POST', '/verify', params, headers) + response = conn.getresponse() + if response.status == 200: + data = simplejson.loads(response.read()) + email = data.get('email') + if email: + return email + else: + message = unicode(data) + message += '\nMost likely base url in /settings/QA_SITE_SETTINGS/ is incorrect' + raise ImproperlyConfigured(message) + #todo: nead more feedback to help debug fail cases + return None |