Skip to content

Commit

Permalink
Merge pull request #588 from Ouranosinc/fix-auth-control-header
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Sep 8, 2023
2 parents 157006c + 4e6aa9c commit 1d602ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Changes

Features / Changes
~~~~~~~~~~~~~~~~~~~~~
* n/a

Bug Fixes
~~~~~~~~~~~~~~~~~~~~~
* Fix returned headers in ``401 Unauthenticated`` response which did not properly employ ``Authentication-Control``
header to return the ``location-when-unauthenticated`` parameter instead of returning it directly as invalid header.
* Add `API` endpoint ``GET /services/{service_name}/resources/{resource_id}`` similar to
existing endpoint ``GET /resources/{resource_id}`` allowing retrieval of a `Resource` details
with prior validation that it lies under the referenced `Service`
Expand Down
15 changes: 11 additions & 4 deletions magpie/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,18 @@ def get_authenticate_headers(request, error_type="invalid_token"):
# WWW-Authenticate: challenge-1 [realm="<>" title="<>" ...],
# challenge-2 [...], ...
# provide URL with both 'domain' and 'uri' which are two variants that can exist, depending on implementation
"WWW-Authenticate": ("Cookie cookie-name=\"{c}\" error=\"{e}\" title=\"{t}\" "
"domain=\"{u}\" uri=\"{u}\" realm=\"{r}\" "
.format(c=cookie_name, e=error_type, u=signin_url, r=hostname, t=title)),
"WWW-Authenticate": (
"Cookie cookie-name=\"{c}\" error=\"{e}\" title=\"{t}\" domain=\"{u}\" uri=\"{u}\" realm=\"{r}\" ".format(
c=cookie_name, e=error_type, u=signin_url, r=hostname, t=title
)
),
# https://tools.ietf.org/html/rfc8053#section-4
# https://tools.ietf.org/html/rfc8053#section-4.3
"Location-When-Unauthenticated": login_url,
"Authentication-Control": (
"Cookie cookie-name=\"{c}\" realm=\"{r}\" location-when-unauthenticated=\"{u}\"".format(
c=cookie_name, r=hostname, u=login_url
)
),
}
return headers

Expand Down

0 comments on commit 1d602ee

Please sign in to comment.