2
Mozilla Persona authentication backend, docs at:
3
https://python-social-auth.readthedocs.io/en/latest/backends/persona.html
5
from ..utils import handle_http_errors
6
from .base import BaseAuth
7
from ..exceptions import AuthFailed, AuthMissingParameter
10
class PersonaAuth(BaseAuth):
11
"""BrowserID authentication backend"""
14
def get_user_id(self, details, response):
15
"""Use BrowserID email as ID"""
16
return details['email']
18
def get_user_details(self, response):
19
"""Return user details, BrowserID only provides Email."""
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],
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']}
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')
43
response = self.get_json('https://browserid.org/verify', data={
44
'assertion': self.data['assertion'],
45
'audience': self.strategy.request_host()
47
if response.get('status') == 'failure':
48
raise AuthFailed(self)
49
kwargs.update({'response': response, 'backend': self})
50
return self.strategy.authenticate(*args, **kwargs)