Permalink
Browse files

Fixed.

  • Loading branch information...
1 parent 94e697f commit a13236d77bf152011514480a3e323d61c096dfb5 @lazarm lazarm committed May 27, 2012
Showing with 10 additions and 15 deletions.
  1. +10 −15 piplmesh/account/backends.py
@@ -1,5 +1,4 @@
-import json, urlparse, urllib
-from httplib import HTTPSConnection
+import json, httplib, urlparse, urllib
from django.conf import settings
from django.core import urlresolvers
@@ -100,42 +99,38 @@ def authenticate(self, twitter_token=None, request=None):
)
user.twitter_token_key = twitter_token.key
user.twitter_token_secret = twitter_token.secret
- print type(user.username), "usernaaaaaaame"
user.save()
return user
class GoogleBackend(MongoEngineBackend):
"""
- GoogleBackend for authentication
+ Google authentication.
"""
def authenticate(self, google_token=None, request=None):
args = {
- 'code': google_token,
'client_id': settings.GOOGLE_CLIENT_ID,
'client_secret': settings.GOOGLE_CLIENT_SECRET,
'redirect_uri': request.build_absolute_uri(urlresolvers.reverse('google_callback')),
+ 'code': google_token,
'grant_type': 'authorization_code',
}
- headers = {"Content-type": "application/x-www-form-urlencoded"}
- conn = HTTPSConnection('accounts.google.com')
- conn.request("POST", '/o/oauth2/token', urllib.urlencode(args), headers)
- response = json.loads(conn.getresponse().read())
- conn.close()
- access_token = response['access_token']
+ token_data = urllib.urlopen('https://accounts.google.com/o/oauth2/token?', urllib.urlencode(args)).read()
+ access_token = json.loads(token_data)['access_token']
- data = urllib.urlopen("https://www.googleapis.com/oauth2/v1/userinfo?access_token=%s" % access_token)
- google_user = json.load(data)
+ user_data = urllib.urlopen("https://www.googleapis.com/oauth2/v1/userinfo?access_token=%s" % access_token)
+ google_user = json.load(user_data)
user, created = self.user_class.objects.get_or_create(
google_id=google_user['id'],
defaults = {
- 'username': google_user['given_name']+google_user['family_name'],
+ 'username': google_user['given_name'] + google_user['family_name'],
'first_name': google_user['given_name'],
'last_name': google_user['family_name'],
'email': google_user['email'],
- 'google_link': google_user['link'],
'gender': google_user['gender'],
+ 'google_link': google_user['link'],
+ 'google_picture_url': google_user['picture'],
}
)
user.google_token = access_token

0 comments on commit a13236d

Please sign in to comment.