Commit 9f37af6d authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_oauth_google_login: Small improvements

parent b8d5d6c1
......@@ -5,6 +5,7 @@ import httplib2
import apiclient.discovery
import oauth2client.client
import socket
from zLOG import LOG, ERROR
def getAccessTokenFromCode(self, code, redirect_uri):
connection_kw = {'host': 'accounts.google.com', 'timeout': 30}
......@@ -29,8 +30,8 @@ def getAccessTokenFromCode(self, code, redirect_uri):
try:
body = json.loads(response.read())
except Exception:
return status, None
except Exception, error_str:
return status, {"error": error_str}
try:
return status, body
......@@ -45,8 +46,9 @@ def getUserId(access_token):
).authorize(httplib2.Http())
service = apiclient.discovery.build("oauth2", "v1", http=http)
google_entry = service.userinfo().get().execute()
except Exception:
except Exception, error_str:
google_entry = None
LOG("GoogleLoginUtility", ERROR, error_str)
finally:
socket.setdefaulttimeout(timeout)
......
......@@ -14,7 +14,7 @@ elif code is not None:
status, response_dict = context.ERP5Site_getAccessTokenFromCode(
code,
"{0}/ERP5Site_receiveGoogleCallback".format(portal.absolute_url()))
if status != 200:
if status != 200 and response_dict is not None:
return handleError(
" ".join(["%s : %s" % (k,v) for k,v in response_dict.iteritems()]))
if response_dict is not None:
......
......@@ -8,4 +8,4 @@ query = make_query({
'scope': 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
})
context.REQUEST.RESPONSE.redirect('''https://accounts.google.com/o/oauth2/auth?''' + query)
context.REQUEST.RESPONSE.redirect("https://accounts.google.com/o/oauth2/auth?" + query)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment