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

« back to all changes in this revision

Viewing changes to social_core/backends/persona.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
Mozilla Persona authentication backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/persona.html
 
4
"""
 
5
from ..utils import handle_http_errors
 
6
from .base import BaseAuth
 
7
from ..exceptions import AuthFailed, AuthMissingParameter
 
8
 
 
9
 
 
10
class PersonaAuth(BaseAuth):
 
11
    """BrowserID authentication backend"""
 
12
    name = 'persona'
 
13
 
 
14
    def get_user_id(self, details, response):
 
15
        """Use BrowserID email as ID"""
 
16
        return details['email']
 
17
 
 
18
    def get_user_details(self, response):
 
19
        """Return user details, BrowserID only provides Email."""
 
20
        # {'status': 'okay',
 
21
        #  'audience': 'localhost:8000',
 
22
        #  'expires': 1328983575529,
 
23
        #  'email': 'name@server.com',
 
24
        #  'issuer': 'browserid.org'}
 
25
        email = response['email']
 
26
        return {'username': email.split('@', 1)[0],
 
27
                'email': email,
 
28
                'fullname': '',
 
29
                'first_name': '',
 
30
                'last_name': ''}
 
31
 
 
32
    def extra_data(self, user, uid, response, details=None, *args, **kwargs):
 
33
        """Return users extra data"""
 
34
        return {'audience': response['audience'],
 
35
                'issuer': response['issuer']}
 
36
 
 
37
    @handle_http_errors
 
38
    def auth_complete(self, *args, **kwargs):
 
39
        """Completes loging process, must return user instance"""
 
40
        if 'assertion' not in self.data:
 
41
            raise AuthMissingParameter(self, 'assertion')
 
42
 
 
43
        response = self.get_json('https://browserid.org/verify', data={
 
44
            'assertion': self.data['assertion'],
 
45
            'audience': self.strategy.request_host()
 
46
        }, method='POST')
 
47
        if response.get('status') == 'failure':
 
48
            raise AuthFailed(self)
 
49
        kwargs.update({'response': response, 'backend': self})
 
50
        return self.strategy.authenticate(*args, **kwargs)