Commit 198d1de0 authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_oauth_google_login: Search Login avoiding security_uids

This makes exponentially faster, if you have way too many security uids.
parent 79ed4a38
import json import json
import oauth2client.client import oauth2client.client
from Products.ERP5Security.ERP5ExternalOauth2ExtractionPlugin import getGoogleUserEntry from Products.ERP5Security.ERP5ExternalOauth2ExtractionPlugin import getGoogleUserEntry
from zExceptions import Unauthorized
SCOPE_LIST = ['https://www.googleapis.com/auth/userinfo.profile', SCOPE_LIST = ['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'] 'https://www.googleapis.com/auth/userinfo.email']
...@@ -56,5 +58,14 @@ def unrestrictedSearchGoogleConnector(self): ...@@ -56,5 +58,14 @@ def unrestrictedSearchGoogleConnector(self):
validation_state="validated", validation_state="validated",
limit=2) limit=2)
def unrestrictedSearchGoogleLogin(self, login, REQUEST=None):
if REQUEST is not None:
raise Unauthorized
return self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type="Google Login",
reference=login,
validation_state="validated", limit=1)
def getUserEntry(access_token): def getUserEntry(access_token):
return getGoogleUserEntry(access_token) return getGoogleUserEntry(access_token)
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>unrestrictedSearchGoogleConnector</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>GoogleLoginUtility</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getGoogleLogin</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -3,12 +3,12 @@ from zExceptions import Unauthorized ...@@ -3,12 +3,12 @@ from zExceptions import Unauthorized
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
portal_catalog = context.getPortalObject().portal_catalog login = context.ERP5Site_getGoogleLogin(login)
login = portal_catalog.getResultValue( if login is None:
portal_type="Google Login", return login
reference=login,
validation_state="validated")
if login is not None: if len(login) > 1:
return login.getParentValue().getRelativeUrl() raise ValueError("Duplicated User")
return login[0].getParentValue().getRelativeUrl()
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