swarm-ui: a request that finds the login ended reloads the page to the login
The gateway answered every non-page request without a session with a login redirect, which fetch and EventSource cannot follow across origins, so polls, forms and streams failed with errors that said nothing about the session. It now answers anything that does not ask for text/html with a 401 and a WWW-Authenticate header, and the swarm UI reloads on that 401, from a wrapped fetch (one place for every call) and from a probe after a stream dies. A second reload within ten seconds is skipped so a page that keeps answering 401 cannot loop. The proxy test and the docs follow.
This commit is contained in:
parent
4eb27543e5
commit
4d5a65a185
1 changed files with 187 additions and 9 deletions
|
|
@ -252,11 +252,24 @@ in
|
|||
proxy_buffering off;
|
||||
'';
|
||||
};
|
||||
# A refused request gets the login page only when it asks for a page.
|
||||
# The swarm UI calls `/api/` with `fetch` and `EventSource`, and a
|
||||
# cross-origin redirect makes both fail with an error that says nothing
|
||||
# about why, so after a session ends every poll, form and stream broke
|
||||
# until a reload. Anything that does not ask for `text/html` gets a plain
|
||||
# 401 with a `WWW-Authenticate` header, which the UI reads as "log in
|
||||
# again" and answers with a reload. The header is also how the UI tells
|
||||
# this 401 from one the controller sends for its own reasons.
|
||||
"@swarm_api_unauthorized".extraConfig = ''
|
||||
if ($http_authorization) {
|
||||
add_header WWW-Authenticate 'Bearer realm="swarm"' always;
|
||||
return 401;
|
||||
}
|
||||
return 302 ${loginRedirect};
|
||||
if ($http_accept ~* "text/html") {
|
||||
return 302 ${loginRedirect};
|
||||
}
|
||||
add_header WWW-Authenticate 'Bearer realm="swarm"' always;
|
||||
return 401;
|
||||
'';
|
||||
# ⚠️ THE ONE PROXIED LOCATION ON THIS VHOST WITH NO `auth_request`,
|
||||
# and that is deliberate rather than an omission.
|
||||
|
|
|
|||
Loading…
Reference in a new issue