Commit f2a684f0 authored by Jérome Perrin's avatar Jérome Perrin

oauth_facebook_login: python3 compatibility

parent cd3833b2
...@@ -21,8 +21,8 @@ elif code is not None: ...@@ -21,8 +21,8 @@ elif code is not None:
code, code,
"{0}/ERP5Site_callbackFacebookLogin".format(context.absolute_url())) "{0}/ERP5Site_callbackFacebookLogin".format(context.absolute_url()))
if response_dict is not None: if response_dict is not None:
access_token = response_dict['access_token'].encode('utf-8') access_token = response_dict['access_token']
hash_str = context.Base_getHMAC(access_token, access_token) hash_str = context.Base_getHMAC(access_token.encode('utf-8'), access_token.encode('utf-8'))
context.setAuthCookie(response, '__ac_facebook_hash', hash_str) context.setAuthCookie(response, '__ac_facebook_hash', hash_str)
# store timestamp in second since the epoch in UTC is enough # store timestamp in second since the epoch in UTC is enough
......
...@@ -39,6 +39,7 @@ from AccessControl.SecurityManagement import getSecurityManager, \ ...@@ -39,6 +39,7 @@ from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager setSecurityManager, newSecurityManager
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
import time import time
import six
from six.moves import urllib from six.moves import urllib
import json import json
from zLOG import LOG, ERROR, INFO from zLOG import LOG, ERROR, INFO
...@@ -240,11 +241,14 @@ def getFacebookUserEntry(token): ...@@ -240,11 +241,14 @@ def getFacebookUserEntry(token):
if facebook_entry is not None: if facebook_entry is not None:
# sanitise value # sanitise value
for k in ('name', 'id'): for k in ('name', 'id'):
v = facebook_entry[k]
if six.PY2:
v = v.encode('utf-8')
try: try:
if k == 'id': if k == 'id':
user_entry['reference'] = facebook_entry[k].encode('utf-8') user_entry['reference'] = v
else: else:
user_entry[k] = facebook_entry[k].encode('utf-8') user_entry[k] = v
except KeyError: except KeyError:
raise ValueError(facebook_entry) raise ValueError(facebook_entry)
return user_entry return user_entry
......
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