From: Stas Kravets Date: Mon, 17 Oct 2011 13:48:11 +0000 (+0400) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=2c6fbec9d5740b428e782dd18e6ac37861ac5fc8;p=django-social-auth.git Merge remote-tracking branch 'upstream/master' Conflicts: social_auth/backends/__init__.py --- 2c6fbec9d5740b428e782dd18e6ac37861ac5fc8 diff --cc social_auth/backends/contrib/yandex.py index 5155d09,0000000..fee08b8 mode 100644,000000..100644 --- a/social_auth/backends/contrib/yandex.py +++ b/social_auth/backends/contrib/yandex.py @@@ -1,48 -1,0 +1,53 @@@ +""" +Yandex OpenID support. + +This contribution adds support for Yandex.ru OpenID service in the form +openid.yandex.ru/user. Username is retrieved from the identity url. + +If username is not specified, OpenID 2.0 url used for authentication. +""" ++import logging ++logger = logging.getLogger(__name__) ++ +import urlparse + +from social_auth.backends import OpenIDBackend, OpenIdAuth, USERNAME + + +# Yandex conf +YANDEX_URL = 'http://openid.yandex.ru/%s' +YANDEX_USER_FIELD = 'openid_ya_user' +YANDEX_OID_2_URL = 'http://yandex.ru' + + +class YandexBackend(OpenIDBackend): + """Yandex OpenID authentication backend""" + name = 'yandex' + + def get_user_details(self, response): + """Generate username from identity url""" + values = super(YandexBackend, self).get_user_details(response) + values[USERNAME] = values.get(USERNAME) or \ + urlparse.urlsplit(response.identity_url)\ + .path.strip('/') - ++ ++ values['email'] = values.get('email') or '' ++ + return values + + +class YandexAuth(OpenIdAuth): + """Yandex OpenID authentication""" + AUTH_BACKEND = YandexBackend + + def openid_url(self): + """Returns Yandex authentication URL""" + if YANDEX_USER_FIELD not in self.data: + return YANDEX_OID_2_URL + else: + return YANDEX_URL % self.data[YANDEX_USER_FIELD] + +# Backend definition +BACKENDS = { + 'yandex': YandexAuth, +}