~ubuntu-branches/debian/sid/social-auth-core/sid

« back to all changes in this revision

Viewing changes to social_core/backends/livejournal.py

  • Committer: Package Import Robot
  • Author(s): Andre Bianchi
  • Date: 2018-02-22 19:49:12 UTC
  • Revision ID: package-import@ubuntu.com-20180222194912-4lqv8mlhnqc4ncd3
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
LiveJournal OpenId backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/livejournal.html
 
4
"""
 
5
from six.moves.urllib_parse import urlsplit
 
6
 
 
7
from .open_id import OpenIdAuth
 
8
from ..exceptions import AuthMissingParameter
 
9
 
 
10
 
 
11
class LiveJournalOpenId(OpenIdAuth):
 
12
    """LiveJournal OpenID authentication backend"""
 
13
    name = 'livejournal'
 
14
 
 
15
    def get_user_details(self, response):
 
16
        """Generate username from identity url"""
 
17
        values = super(LiveJournalOpenId, self).get_user_details(response)
 
18
        values['username'] = values.get('username') or \
 
19
                             urlsplit(response.identity_url)\
 
20
                                .netloc.split('.', 1)[0]
 
21
        return values
 
22
 
 
23
    def openid_url(self):
 
24
        """Returns LiveJournal authentication URL"""
 
25
        if not self.data.get('openid_lj_user'):
 
26
            raise AuthMissingParameter(self, 'openid_lj_user')
 
27
        return 'http://{0}.livejournal.com'.format(self.data['openid_lj_user'])