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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
amrani
erp5
Commits
a3e448f1
Commit
a3e448f1
authored
Sep 26, 2017
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Security: Define getFacebookUserEntry to reduce code duplication
This method and call is duplicated on several places
parent
b0923a89
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
27 deletions
+29
-27
product/ERP5Security/ERP5ExternalOauth2ExtractionPlugin.py
product/ERP5Security/ERP5ExternalOauth2ExtractionPlugin.py
+29
-27
No files found.
product/ERP5Security/ERP5ExternalOauth2ExtractionPlugin.py
View file @
a3e448f1
...
@@ -226,12 +226,40 @@ class ERP5ExternalOauth2ExtractionPlugin:
...
@@ -226,12 +226,40 @@ class ERP5ExternalOauth2ExtractionPlugin:
creds
[
'remote_address'
]
=
request
.
get
(
'REMOTE_ADDR'
,
''
)
creds
[
'remote_address'
]
=
request
.
get
(
'REMOTE_ADDR'
,
''
)
return
creds
return
creds
def
getFacebookUserEntry
(
token
):
if
facebook
is
None
:
LOG
(
'ERP5FacebookExtractionPlugin'
,
INFO
,
'No facebook module, install facebook-sdk package. '
'Authentication disabled.'
)
return
None
timeout
=
socket
.
getdefaulttimeout
()
try
:
# require really fast interaction
socket
.
setdefaulttimeout
(
5
)
facebook_entry
=
facebook
.
GraphAPI
(
token
).
get_object
(
"me"
)
finally
:
socket
.
setdefaulttimeout
(
timeout
)
user_entry
=
{}
if
facebook_entry
is
not
None
:
# sanitise value
for
k
in
(
'name'
,
'id'
):
try
:
if
k
==
'id'
:
user_entry
[
'reference'
]
=
facebook_entry
[
k
].
encode
(
'utf-8'
)
else
:
user_entry
[
k
]
=
facebook_entry
[
k
].
encode
(
'utf-8'
)
except
KeyError
:
raise
ValueError
(
facebook_entry
)
return
user_entry
class
ERP5FacebookExtractionPlugin
(
ERP5ExternalOauth2ExtractionPlugin
,
BasePlugin
):
class
ERP5FacebookExtractionPlugin
(
ERP5ExternalOauth2ExtractionPlugin
,
BasePlugin
):
"""
"""
Plugin to authenicate as machines.
Plugin to authenicate as machines.
"""
"""
meta_type
=
"ERP5 Facebook Extraction Plugin"
meta_type
=
"ERP5 Facebook Extraction Plugin"
login_portal_type
=
"Facebook Login"
cookie_name
=
"__ac_facebook_hash"
cookie_name
=
"__ac_facebook_hash"
cache_factory_name
=
"facebook_server_auth_token_cache_factory"
cache_factory_name
=
"facebook_server_auth_token_cache_factory"
...
@@ -239,33 +267,7 @@ class ERP5FacebookExtractionPlugin(ERP5ExternalOauth2ExtractionPlugin, BasePlugi
...
@@ -239,33 +267,7 @@ class ERP5FacebookExtractionPlugin(ERP5ExternalOauth2ExtractionPlugin, BasePlugi
return
cache_value
return
cache_value
def
getUserEntry
(
self
,
token
):
def
getUserEntry
(
self
,
token
):
if
facebook
is
None
:
return
getFacebookUserDict
(
token
)
LOG
(
'ERP5FacebookExtractionPlugin'
,
INFO
,
'No facebook module, install facebook-sdk package. '
'Authentication disabled.'
)
return
None
timeout
=
socket
.
getdefaulttimeout
()
try
:
# require really fast interaction
socket
.
setdefaulttimeout
(
5
)
facebook_entry
=
facebook
.
GraphAPI
(
token
).
get_object
(
"me"
)
except
Exception
:
facebook_entry
=
None
finally
:
socket
.
setdefaulttimeout
(
timeout
)
user_entry
=
{}
if
facebook_entry
is
not
None
:
# sanitise value
try
:
for
k
in
(
'first_name'
,
'last_name'
,
'id'
,
'email'
):
if
k
==
'id'
:
user_entry
[
'reference'
]
=
facebook_entry
[
k
].
encode
(
'utf-8'
)
else
:
user_entry
[
k
]
=
facebook_entry
[
k
].
encode
(
'utf-8'
)
except
KeyError
:
user_entry
=
None
return
user_entry
class
ERP5GoogleExtractionPlugin
(
ERP5ExternalOauth2ExtractionPlugin
,
BasePlugin
):
class
ERP5GoogleExtractionPlugin
(
ERP5ExternalOauth2ExtractionPlugin
,
BasePlugin
):
"""
"""
...
...
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