0
Follow
0
View

How to add a class to python social auth lib?

latashu 注册会员
2023-01-25 17:00

See examples in doc.

Example class for openID:

from social_core.backends.open_id import OpenIdAuth
from social_core.exceptions import AuthMissingParameter

class LiveJournalOpenId(OpenIdAuth):
"""LiveJournal OpenID authentication backend"""
name = 'livejournal'

def get_user_details(self, response):
    """Generate username from identity url"""
    values = super(LiveJournalOpenId, self).get_user_details(response)
    values['username'] = values.get('username') or \
                         urlparse.urlsplit(response.identity_url)\
                                    .netloc.split('.', 1)[0]
    return values

def openid_url(self):
    """Returns LiveJournal authentication URL"""
    if not self.data.get('openid_lj_user'):
        raise AuthMissingParameter(self, 'openid_lj_user')
    return 'http://%s.livejournal.com' % self.data['openid_lj_user']

About the Author

Question Info

Publish Time
2023-01-25 17:00
Update Time
2023-01-25 17:00