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

fix(ui): trigger page reload on 401 (fix basic auth) #3825

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

oandrew
Copy link
Contributor

@oandrew oandrew commented Jul 22, 2024

Changes

Throw exception when 401 returned from /auth-enabled to trigger page reload. This is needed for http basic auth to work properly.

Details

I run zwave-js-ui behind basic http auth and get "Unexpected end of JSON input" error after browser restart:
Screenshot 2024-07-22 at 2 33 55 PM

This happens when 401 status is returned since Chrome keeps auth only until browser restart.
Typically Chrome would display the auth popup in this case but turns out it doesn't work requests made by service workers:
https://issues.chromium.org/issues/40474438

This is essentially the same issue as #3427

FWIW Without this PR, it can be "fixed" with the following Caddy config (send 302 when Authorization header is missing)

(auth) {
        basicauth {
                ...
        }
}

zwave.mydomain.com {
        @auth_check {
                path /api/auth-enabled
                header !Authorization
        }
        # trigger redirect when auth header not set
        handle @auth_check {
               redir zwave.mydomain.com 302
        }
        handle {
                import auth
                reverse_proxy 127.0.0.1:8091
        }
}

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10048985471

Details

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 21.021%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/apis/ConfigApis.js 0 1 0.0%
Totals Coverage Status
Change from base Build 10044063312: 0.0%
Covered Lines: 3899
Relevant Lines: 19728

💛 - Coveralls

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertsLando robertsLando merged commit 176ef24 into zwave-js:master Jul 23, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants