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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | #models.py
from django.conf import settings
from django.contrib.auth.models import User, check_password
from django.contrib.auth.backends import ModelBackend
from django.utils.translation import ugettext as _
import gdata.contacts
import gdata.contacts.service
class GoogleAuthenticator(ModelBackend):
def __init__(self):
"""Make autentication using a google account."""
self.google_service = gdata.contacts.service.ContactsService()
def authenticate(self, username=None, password=None):
user = None
try:
self.google_service.email = username
self.google_service.password = password
self.google_service.source = 'CampanhaEleicoesGerenciamento'
self.google_service.ProgrammaticLogin()
login_valid = True
pwd_valid = True
except gdata.service.BadAuthentication:
print "A autenticacao falhou"
login_valid = True
pwd_valid = True
return None
if login_valid and pwd_valid:
try:
user = User.objects.get(email=username)
except User.DoesNotExist:
return None
return user
return None
#settings.py
# Customize authentication backend
AUTHENTICATION_BACKENDS = (
'campanha_gerenciamento.custom.models.GoogleAuthenticator',
)
|
Comments
Nice but really poor user confidence-experience. With this you'd be able to capture a user's username & password all in clear text and thus you can access his email, saved searches, google checkout, etc.
I would not go near a service that uses this snippet. That's what OAuth was built to solve.
#