Login

Google Authentification

Author:
marcossousa
Posted:
January 31, 2010
Language:
Python
Version:
1.1
Tags:
admin google
Score:
1 (after 1 ratings)

Google autentication

 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',
)

More like this

  1. Google Analytics Template Tag by blinks 7 years, 8 months ago
  2. Google Contacts import by henriklied 7 years, 3 months ago
  3. Django google maps v3 snipplet by summerisgone 4 years, 11 months ago
  4. Google Account authentication by Hangya 4 years, 10 months ago
  5. Google AppEngine Login Decorator by cmcavoy 7 years, 2 months ago

Comments

peterbe (on January 31, 2010):

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.

#

Please login first before commenting.