at the moment:
* `Google OpenID`_
+ * `Google OAuth`_
* `Yahoo OpenID`_
++ * `LiveJournal OpenID`_
* OpenId_ like myOpenID_
* `Twitter OAuth`_
* `Facebook OAuth`_
'social_auth.backends.TwitterBackend',
'social_auth.backends.FacebookBackend',
'social_auth.backends.OrkutBackend',
+ 'social_auth.backends.GoogleOAuthBackend',
'social_auth.backends.GoogleBackend',
'social_auth.backends.YahooBackend',
++ 'social_auth.backends.LiveJournalBackend',
'social_auth.backends.OpenIDBackend',
'django.contrib.auth.backends.ModelBackend',
)
user.gender = response.get('gender')
return True
++New data updating is made automatically but could be disabled and left only to
++signal handler if this setting value::
++
++ SOCIAL_AUTH_CHANGE_SIGNAL_ONLY = False
++
++is set to True.
++
------
OpenId
.. _caioariede: https://github.com/caioariede
.. _krvss: https://github.com/krvss
.. _jezdez: https://github.com/jezdez
++.. _LiveJournal OpenID: http://www.livejournal.com/support/faqbrowse.bml?faqid=283
from .store import DjangoOpenIDStore
from .backends import TwitterBackend, OrkutBackend, FacebookBackend, \
- OpenIDBackend, GoogleBackend, YahooBackend, LiveJournalBackend
+ OpenIDBackend, GoogleBackend, YahooBackend, \
- GoogleOAuthBackend
++ GoogleOAuthBackend, LiveJournalBackend
from .conf import AX_ATTRS, SREG_ATTR, OPENID_ID_FIELD, SESSION_NAME, \
OPENID_GOOGLE_URL, OPENID_YAHOO_URL, TWITTER_SERVER, \
+ OPENID_LIVEJOURNAL_URL, OPENID_LIVEJOURNAL_USER_FIELD, \
TWITTER_REQUEST_TOKEN_URL, TWITTER_ACCESS_TOKEN_URL, \
TWITTER_AUTHORIZATION_URL, TWITTER_CHECK_AUTH, \
FACEBOOK_CHECK_AUTH, FACEBOOK_AUTHORIZATION_URL, \
"""Return Yahoo OpenID service url"""
return OPENID_YAHOO_URL
-
+
+ class LiveJournalAuth(OpenIdAuth):
+ """LiveJournal OpenID authentication"""
+ AUTH_BACKEND = LiveJournalBackend
++
+ def uses_redirect(self):
+ """LiveJournal uses redirect"""
+ return True
- """Returns LJ authentication URL"""
- if self.request.method != 'POST' or not self.request.POST.get(OPENID_LIVEJOURNAL_USER_FIELD):
++
+ def openid_url(self):
- return OPENID_LIVEJOURNAL_URL % self.request.POST[OPENID_LIVEJOURNAL_USER_FIELD]
++ """Returns LiveJournal authentication URL"""
++ if self.request.method != 'POST' or \
++ not self.request.POST.get(OPENID_LIVEJOURNAL_USER_FIELD):
+ raise ValueError, 'Missing LiveJournal user identifier'
++ return OPENID_LIVEJOURNAL_URL % \
++ self.request.POST[OPENID_LIVEJOURNAL_USER_FIELD]
++
+
class BaseOAuth(BaseAuth):
"""OAuth base class"""
def __init__(self, request, redirect):
'twitter': TwitterAuth,
'facebook': FacebookAuth,
'google': GoogleAuth,
+ 'google-oauth': GoogleOAuth,
'yahoo': YahooAuth,
+ 'livejournal': LiveJournalAuth,
'orkut': OrkutAuth,
'openid': OpenIdAuth,
}
"""
Authentication backeds for django.contrib.auth AUTHENTICATION_BACKENDS setting
"""
++import urlparse
from os import urandom
from openid.extensions import ax, sreg
"""Update user details with (maybe) new data. Username is not
changed if associating a new credential."""
changed = False
- for name, value in details.iteritems():
- # not update username if user already exists
- if not new_user and name == USERNAME:
- continue
- if value and value != getattr(user, name, value):
- setattr(user, name, value)
- changed = True
-
+
++ # check if values update should be left to signals handlers only
+ if not getattr(settings, 'SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', False):
+ for name, value in details.iteritems():
+ # not update username if user already exists
+ if not new_user and name == USERNAME:
+ continue
+ if value and value != getattr(user, name, value):
+ setattr(user, name, value)
+ changed = True
+
# Fire a pre-update signal sending current backend instance,
# user instance (created or retrieved from database), service
# response and processed details, signal handlers must return
# True or False to signal that something has changed
- updated = filter(None, pre_update.send(sender=self, user=user,
+ updated = filter(None, pre_update.send(sender=self.__class__,
+ user=user,
response=response,
details=details))
- if changed or len(updated) > 0:
+ # Looking for at least one update
+ has_update = False
+ for result in updated:
+ if result[1]:
+ has_update = True
+ break
+
+ if changed or has_update:
user.save()
def get_user_id(self, details, response):
class YahooBackend(OpenIDBackend):
"""Yahoo OpenID authentication backend"""
name = 'yahoo'
- """LJ OpenID authentication backend"""
- name = 'livejournal'
+
++
+ class LiveJournalBackend(OpenIDBackend):
++ """LiveJournal OpenID authentication backend"""
++ name = 'livejournal'
++
++ def get_user_details(self, response):
++ """Generate username from identity url"""
++ values = super(LiveJournalBackend, self).get_user_details(response)
++ if not values.get(USERNAME):
++ values[USERNAME] = urlparse.urlsplit(response.identity_url)\
++ .netloc.split('.', 1)[0]
++ return values
SREG_ATTR = ['email', 'fullname', 'nickname']
OPENID_ID_FIELD = 'openid_identifier'
SESSION_NAME = 'openid'
- OPENID_GOOGLE_URL = 'https://www.google.com/accounts/o8/id'
+ OPENID_GOOGLE_URL = 'https://www.google.com/accounts/o8/id'
OPENID_YAHOO_URL = 'http://yahoo.com'
-OPENID_LIVEJOURNAL_USER_FIELD = 'openid_lj_user'
+ OPENID_LIVEJOURNAL_URL = 'http://%s.livejournal.com'
++OPENID_LIVEJOURNAL_USER_FIELD = 'openid_lj_user'