forked from dropbox/questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
25 lines (17 loc) · 780 Bytes
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import mail_admins
from openid.consumer.consumer import SUCCESS
from django_openid_auth.auth import OpenIDBackend
class GoogleAuthBackend(OpenIDBackend):
def authenticate(self, **kwargs):
openid_response = kwargs.get('openid_response')
if openid_response is None:
return None
if openid_response.status != SUCCESS:
return None
email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
domain = email.split("@", 1)[1]
if domain not in getattr(settings, "OPENID_RESTRICT_TO_DOMAINS", tuple()):
return None
return OpenIDBackend.authenticate(self, **kwargs)