Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set authorization bearer header from auth_token cookie #69

Merged
merged 5 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ jobs:
bin/code-analysis
- name: Run tests
run: |
TZ=${{ matrix.tz }} bin/test-coverage
bin/test-coverage
env:
PROXY_BEARER_AUTH: on
TZ: ${{ matrix.tz }}
- name: Upload coverage data to coveralls.io
run: |
pip install coveralls
Expand All @@ -61,4 +64,4 @@ jobs:
pip install --upgrade coveralls
coveralls --service=github --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
5.0.2 (unreleased)
------------------

- Nothing changed yet.
- set authorization bearer header from auth_token cookie
[mamico]


5.0.1 (2023-07-04)
Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ Default ISerializeToJsonSummary adapter

This is a patch for backward compatibility for old volto templates that need a full image scales object.

Authentication Header
---------------------

There is a custom event handler for IPubStart that set authorization bearer header from auth_token cookie.
For details see the `pull-request <https://github.com/RedTurtle/redturtle.volto/pull/69>`_.

This patch is not enabled by default. You need to set an environment variable to `true`: *PROXY_BEARER_AUTH*.

New Criteria
============
Expand Down
1 change: 1 addition & 0 deletions base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ scripts =
[versions]
# Don't use a released version of redturtle.volto
redturtle.volto =
setuptools =
5 changes: 5 additions & 0 deletions src/redturtle/volto/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@
name="redturtle.volto-hiddenprofiles"
/>

<subscriber
for="ZPublisher.interfaces.IPubStart"
handler=".events.manage_auth_token"
/>

</configure>
18 changes: 18 additions & 0 deletions src/redturtle/volto/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os


def manage_auth_token(event):
"""
set authorization header from cookie

see:
https://github.com/plone/plone.restapi/issues/148
https://github.com/plone/plone.restapi/pull/1303
"""
if os.environ.get("PROXY_BEARER_AUTH"):
request = event.request
if getattr(request, "_auth", None):
return
auth_token = request.cookies.get("auth_token")
if auth_token:
request._auth = "Bearer " + auth_token
Loading