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
Carlos Ramos Carreño
erp5
Commits
ba4d4deb
Commit
ba4d4deb
authored
Feb 01, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bearer_token: py3
parent
efc4dc56
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
5 deletions
+13
-5
bt5/erp5_bearer_token/ExtensionTemplateItem/portal_components/extension.erp5.BearerToken.py
...plateItem/portal_components/extension.erp5.BearerToken.py
+8
-0
bt5/erp5_bearer_token/SkinTemplateItem/portal_skins/erp5_bearer_token/Base_extractBearerTokenInformation.py
...s/erp5_bearer_token/Base_extractBearerTokenInformation.py
+2
-2
bt5/erp5_bearer_token/SkinTemplateItem/portal_skins/erp5_bearer_token/Base_getBearerTokenKey.py
.../portal_skins/erp5_bearer_token/Base_getBearerTokenKey.py
+1
-1
bt5/erp5_bearer_token/SkinTemplateItem/portal_skins/erp5_bearer_token/Person_getBearerToken.py
...m/portal_skins/erp5_bearer_token/Person_getBearerToken.py
+1
-1
bt5/erp5_bearer_token/TestTemplateItem/portal_components/test.erp5.testERP5BearerToken.py
...teItem/portal_components/test.erp5.testERP5BearerToken.py
+1
-1
No files found.
bt5/erp5_bearer_token/ExtensionTemplateItem/portal_components/extension.erp5.BearerToken.py
View file @
ba4d4deb
import
hashlib
import
hmac
from
Products.ERP5Type.Cache
import
DEFAULT_CACHE_SCOPE
import
six
CACHE_FACTORY_NAME
=
'bearer_token_cache_factory'
def
getHMAC
(
self
,
key
,
body
):
# type: (erp5.portal_type.Base, bytes, bytes) -> str
digest
=
hmac
.
new
(
key
,
body
,
digestmod
=
hashlib
.
md5
)
return
digest
.
hexdigest
()
...
...
@@ -22,6 +24,10 @@ def _getCacheFactory(self, cache_factory_name):
return
cache_tool
.
getRamCacheRoot
().
get
(
cache_factory_name
)
def
setBearerToken
(
self
,
key
,
body
,
cache_factory_name
=
CACHE_FACTORY_NAME
):
# type: (erp5.portal_type.Base, str, Any, str) -> None
if
not
isinstance
(
key
,
six
.
string_types
):
__traceback_info__
=
key
raise
TypeError
(
"Wrong key type %s"
%
(
type
(
key
)))
cache_factory
=
_getCacheFactory
(
self
,
cache_factory_name
)
cache_duration
=
cache_factory
.
cache_duration
for
cache_plugin
in
cache_factory
.
getCachePluginList
():
...
...
@@ -29,6 +35,8 @@ def setBearerToken(self, key, body, cache_factory_name=CACHE_FACTORY_NAME):
body
,
cache_duration
=
cache_duration
)
def
getBearerToken
(
self
,
key
,
cache_factory_name
=
CACHE_FACTORY_NAME
):
# type: (erp5.portal_type.Base, str, str) -> Any
assert
isinstance
(
key
,
six
.
string_types
)
cache_factory
=
_getCacheFactory
(
self
,
cache_factory_name
)
for
cache_plugin
in
cache_factory
.
getCachePluginList
():
cache_entry
=
cache_plugin
.
get
(
key
,
DEFAULT_CACHE_SCOPE
)
...
...
bt5/erp5_bearer_token/SkinTemplateItem/portal_skins/erp5_bearer_token/Base_extractBearerTokenInformation.py
View file @
ba4d4deb
...
...
@@ -5,9 +5,9 @@ except KeyError:
# not found
return
None
key
=
context
.
getPortalObject
().
portal_preferences
.
getPreferredBearerTokenKey
()
key
=
context
.
getPortalObject
().
portal_preferences
.
getPreferredBearerTokenKey
()
.
encode
()
if
context
.
Base_getHMAC
(
key
,
str
(
token_dict
))
!=
token
:
if
context
.
Base_getHMAC
(
key
,
str
(
token_dict
)
.
encode
(
'utf-8'
)
)
!=
token
:
# bizzare, not valid
return
None
...
...
bt5/erp5_bearer_token/SkinTemplateItem/portal_skins/erp5_bearer_token/Base_getBearerTokenKey.py
View file @
ba4d4deb
if
REQUEST
is
not
None
:
# mini security
return
None
return
context
.
getPortalObject
().
portal_preferences
.
getPreferredBearerTokenKey
(
)
return
(
context
.
getPortalObject
().
portal_preferences
.
getPreferredBearerTokenKey
()
or
''
).
encode
(
'utf-8'
)
bt5/erp5_bearer_token/SkinTemplateItem/portal_skins/erp5_bearer_token/Person_getBearerToken.py
View file @
ba4d4deb
...
...
@@ -14,7 +14,7 @@ token = {
'remote-addr'
:
context
.
REQUEST
.
get
(
'REMOTE_ADDR'
)
}
hmac
=
context
.
Base_getHMAC
(
key
,
str
(
token
))
hmac
=
context
.
Base_getHMAC
(
key
,
str
(
token
)
.
encode
(
'utf-8'
)
)
context
.
Base_setBearerToken
(
hmac
,
token
)
...
...
bt5/erp5_bearer_token/TestTemplateItem/portal_components/test.erp5.testERP5BearerToken.py
View file @
ba4d4deb
...
...
@@ -108,7 +108,7 @@ class TestERP5BearerToken(ERP5TypeTestCase):
'remote-addr'
:
self
.
portal
.
REQUEST
.
get
(
'REMOTE_ADDR'
)
}
hmac
=
self
.
portal
.
Base_getHMAC
(
self
.
portal
.
Base_getBearerTokenKey
(),
str
(
token
))
token
)
.
encode
(
'utf-8'
)
)
self
.
portal
.
Base_setBearerToken
(
hmac
,
token
)
reference
=
self
.
getTokenCredential
(
self
.
portal
.
REQUEST
)
self
.
assertEqual
(
reference
,
None
)
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