Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tristan Cavelier
erp5
Commits
5c833d37
Commit
5c833d37
authored
Jul 09, 2012
by
Łukasz Nowak
Committed by
Rafael Monnerat
Sep 17, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add plugin to extract users from Google profiles..
parent
af257c98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
1 deletion
+119
-1
product/ERP5Security/ERP5ExternalOauth2ExtractionPlugin.py
product/ERP5Security/ERP5ExternalOauth2ExtractionPlugin.py
+73
-1
product/ERP5Security/__init__.py
product/ERP5Security/__init__.py
+10
-0
product/ERP5Security/www/ERP5Security_addERP5GoogleExtractionPlugin.zpt
...curity/www/ERP5Security_addERP5GoogleExtractionPlugin.zpt
+36
-0
No files found.
product/ERP5Security/ERP5ExternalOauth2ExtractionPlugin.py
View file @
5c833d37
...
@@ -47,6 +47,13 @@ try:
...
@@ -47,6 +47,13 @@ try:
except
ImportError
:
except
ImportError
:
facebook
=
None
facebook
=
None
try
:
import
apiclient.discovery
import
httplib2
import
oauth2client.client
except
ImportError
:
httplib2
=
None
#Form for new plugin in ZMI
#Form for new plugin in ZMI
manage_addERP5FacebookExtractionPluginForm
=
PageTemplateFile
(
manage_addERP5FacebookExtractionPluginForm
=
PageTemplateFile
(
'www/ERP5Security_addERP5FacebookExtractionPlugin'
,
globals
(),
'www/ERP5Security_addERP5FacebookExtractionPlugin'
,
globals
(),
...
@@ -65,6 +72,24 @@ def addERP5FacebookExtractionPlugin(dispatcher, id, title=None, REQUEST=None):
...
@@ -65,6 +72,24 @@ def addERP5FacebookExtractionPlugin(dispatcher, id, title=None, REQUEST=None):
'ERP5FacebookExtractionPlugin+added.'
'ERP5FacebookExtractionPlugin+added.'
%
dispatcher
.
absolute_url
())
%
dispatcher
.
absolute_url
())
#Form for new plugin in ZMI
manage_addERP5GoogleExtractionPluginForm
=
PageTemplateFile
(
'www/ERP5Security_addERP5GoogleExtractionPlugin'
,
globals
(),
__name__
=
'manage_addERP5GoogleExtractionPluginForm'
)
def
addERP5GoogleExtractionPlugin
(
dispatcher
,
id
,
title
=
None
,
REQUEST
=
None
):
""" Add a ERP5GoogleExtractionPlugin to a Pluggable Auth Service. """
plugin
=
ERP5GoogleExtractionPlugin
(
id
,
title
)
dispatcher
.
_setObject
(
plugin
.
getId
(),
plugin
)
if
REQUEST
is
not
None
:
REQUEST
[
'RESPONSE'
].
redirect
(
'%s/manage_workspace'
'?manage_tabs_message='
'ERP5GoogleExtractionPlugin+added.'
%
dispatcher
.
absolute_url
())
class
ERP5ExternalOauth2ExtractionPlugin
:
class
ERP5ExternalOauth2ExtractionPlugin
:
cache_factory_name
=
'extrenal_oauth2_token_cache_factory'
cache_factory_name
=
'extrenal_oauth2_token_cache_factory'
...
@@ -136,7 +161,6 @@ class ERP5ExternalOauth2ExtractionPlugin:
...
@@ -136,7 +161,6 @@ class ERP5ExternalOauth2ExtractionPlugin:
# no token
# no token
return
DumbHTTPExtractor
().
extractCredentials
(
request
)
return
DumbHTTPExtractor
().
extractCredentials
(
request
)
# token is available
# token is available
user
=
None
user
=
None
user_entry
=
None
user_entry
=
None
...
@@ -226,6 +250,49 @@ class ERP5FacebookExtractionPlugin(ERP5ExternalOauth2ExtractionPlugin, BasePlugi
...
@@ -226,6 +250,49 @@ class ERP5FacebookExtractionPlugin(ERP5ExternalOauth2ExtractionPlugin, BasePlugi
user_entry
=
None
user_entry
=
None
return
user_entry
return
user_entry
class
ERP5GoogleExtractionPlugin
(
ERP5ExternalOauth2ExtractionPlugin
,
BasePlugin
):
"""
Plugin to authenicate as machines.
"""
meta_type
=
"ERP5 Google Extraction Plugin"
prefix
=
'go_'
header_string
=
'google'
def
getUserEntry
(
self
,
token
):
if
httplib2
is
None
:
LOG
(
'ERP5GoogleExtractionPlugin'
,
INFO
,
'No Google modules available, please install google-api-python-client '
'package. Authentication disabled..'
)
return
None
timeout
=
socket
.
getdefaulttimeout
()
try
:
# require really fast interaction
socket
.
setdefaulttimeout
(
5
)
http
=
oauth2client
.
client
.
AccessTokenCredentials
(
token
,
'ERP5 Client'
).
authorize
(
httplib2
.
Http
())
service
=
apiclient
.
discovery
.
build
(
"oauth2"
,
"v1"
,
http
=
http
)
google_entry
=
service
.
userinfo
().
get
().
execute
()
except
Exception
:
google_entry
=
None
finally
:
socket
.
setdefaulttimeout
(
timeout
)
user_entry
=
{}
if
google_entry
is
not
None
:
# sanitise value
try
:
for
k
in
((
'first_name'
,
'given_name'
),
(
'last_name'
,
'family_name'
),
(
'reference'
,
'id'
),
(
'email'
,
'email'
)):
value
=
google_entry
[
k
[
1
]].
encode
(
'utf-8'
)
if
k
[
0
]
==
'reference'
:
value
=
self
.
prefix
+
value
user_entry
[
k
[
0
]]
=
value
except
KeyError
:
user_entry
=
None
return
user_entry
#List implementation of class
#List implementation of class
classImplements
(
ERP5FacebookExtractionPlugin
,
classImplements
(
ERP5FacebookExtractionPlugin
,
...
@@ -233,3 +300,8 @@ classImplements( ERP5FacebookExtractionPlugin,
...
@@ -233,3 +300,8 @@ classImplements( ERP5FacebookExtractionPlugin,
)
)
InitializeClass
(
ERP5FacebookExtractionPlugin
)
InitializeClass
(
ERP5FacebookExtractionPlugin
)
classImplements
(
ERP5GoogleExtractionPlugin
,
plugins
.
ILoginPasswordHostExtractionPlugin
)
InitializeClass
(
ERP5GoogleExtractionPlugin
)
product/ERP5Security/__init__.py
View file @
5c833d37
...
@@ -66,6 +66,7 @@ registerMultiPlugin(ERP5KeyAuthPlugin.ERP5KeyAuthPlugin.meta_type)
...
@@ -66,6 +66,7 @@ registerMultiPlugin(ERP5KeyAuthPlugin.ERP5KeyAuthPlugin.meta_type)
registerMultiPlugin
(
ERP5ExternalAuthenticationPlugin
.
ERP5ExternalAuthenticationPlugin
.
meta_type
)
registerMultiPlugin
(
ERP5ExternalAuthenticationPlugin
.
ERP5ExternalAuthenticationPlugin
.
meta_type
)
registerMultiPlugin
(
ERP5BearerExtractionPlugin
.
ERP5BearerExtractionPlugin
.
meta_type
)
registerMultiPlugin
(
ERP5BearerExtractionPlugin
.
ERP5BearerExtractionPlugin
.
meta_type
)
registerMultiPlugin
(
ERP5ExternalOauth2ExtractionPlugin
.
ERP5FacebookExtractionPlugin
.
meta_type
)
registerMultiPlugin
(
ERP5ExternalOauth2ExtractionPlugin
.
ERP5FacebookExtractionPlugin
.
meta_type
)
registerMultiPlugin
(
ERP5ExternalOauth2ExtractionPlugin
.
ERP5GoogleExtractionPlugin
.
meta_type
)
def
initialize
(
context
):
def
initialize
(
context
):
...
@@ -141,6 +142,15 @@ def initialize(context):
...
@@ -141,6 +142,15 @@ def initialize(context):
,
icon
=
'www/portal.gif'
,
icon
=
'www/portal.gif'
)
)
context
.
registerClass
(
ERP5ExternalOauth2ExtractionPlugin
.
ERP5GoogleExtractionPlugin
,
permission
=
ManageUsers
,
constructors
=
(
ERP5ExternalOauth2ExtractionPlugin
.
manage_addERP5GoogleExtractionPluginForm
,
ERP5ExternalOauth2ExtractionPlugin
.
addERP5GoogleExtractionPlugin
,
)
,
visibility
=
None
,
icon
=
'www/portal.gif'
)
from
AccessControl.SecurityInfo
import
ModuleSecurityInfo
from
AccessControl.SecurityInfo
import
ModuleSecurityInfo
ModuleSecurityInfo
(
'Products.ERP5Security.ERP5UserManager'
).
declarePublic
(
ModuleSecurityInfo
(
'Products.ERP5Security.ERP5UserManager'
).
declarePublic
(
'getUserByLogin'
)
'getUserByLogin'
)
product/ERP5Security/www/ERP5Security_addERP5GoogleExtractionPlugin.zpt
0 → 100644
View file @
5c833d37
<h1 tal:replace="structure context/manage_page_header">PAGE HEADER</h1>
<h2 tal:define="form_title string:Add ERP5 Google Extraction Plugin"
tal:replace="structure context/manage_form_title">FORM TITLE</h2>
<p class="form-help">Please input the configuration</p>
<form action="addERP5GoogleExtractionPlugin" method="POST">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-label">
Id
</div>
</td>
<td align="left" valign="top">
<input type="text" name="id" size="40" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Title
</div>
</td>
<td align="left" valign="top">
<input type="text" name="title" size="40" />
</td>
</tr>
<tr>
<td colspan="2"> <input type="submit" value="add plugin"/>
</td>
</tr>
</table>
</form>
<h1 tal:replace="structure context/manage_page_footer">PAGE FOOTER</h1>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment