Skip to content

Allow re-authenticating a server from settings - #6128

Merged
bgoncal merged 2 commits into
mainfrom
reauthenticate-server
Oct 25, 2026
Merged

bgoncal merged 2 commits into
mainfrom
reauthenticate-server

Conversation

@bgoncal

@bgoncal bgoncal commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

AI Policy

Select exactly one option that describes AI usage in this contribution:

  • I have not used AI for this contribution.
  • AI assistance was used for this contribution.
  • AI fully generated the code for this contribution, but I've reviewed and understood it before submitting and will respond without AI during review.

Summary

Adds a way to sign in to a server again without removing it, for example after a password change or to switch users.

  • Re-authenticate row in Server Details, and in the long-press menu of a server in Settings.
  • Asks which URL to use when the server has more than one.
  • Asks for a client certificate when the server requires one and none is stored.
  • The server's web view reloads after signing in.

Screenshots

Light Dark

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#1462

Any other notes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Undefined test macros block compilation, credential replacement can race with an existing refresh, and Catalyst certificate import omits the established presentation workaround.

3 open issues
What changed in this PR

Adds settings-based re-authentication for existing Home Assistant servers without removing their configuration, reusing the recovered-server login flow.

Changes:

  • Adds re-authentication actions in Server Details and server context menus, with URL selection and certificate import.
  • Shares token replacement logic and reloads the affected frontend after sign-in.
  • Adds localized labels and tests for authentication, presentation, and settings updates.
File Description
Tests/​App/​WebView/​WebViewControllerTests.swift Tests recovery from the logged-out state after re-authentication.
Tests/​App/​Settings/​ServerReauthenticationModifier.test.swift Tests picker, certificate, login, and error presentation.
Tests/​App/​Settings/​ServerReauthenticationModel.test.swift Tests settings authentication state and outcomes.
Tests/​App/​Settings/​ConnectionSettingsViewModel.test.swift Tests certificate updates from server changes.
Tests/​App/​Settings/​ConnectionSettingsView.test.swift Adds progress-state snapshot coverage and search verification.
Tests/​App/​Container/​ServerReauthenticatorTests.swift Tests shared token replacement and redirect handling.
Tests/​App/​Container/​RecoveredServerReauthViewModelTests.swift Updates the certificate-check test dependency.
Tests/​App/​Container/​OnboardingStateObservableTests.swift Updates shared authentication test dependencies.
Sources/​Shared/​Resources/​Swiftgen/​Strings.swift Adds generated re-authentication string accessors.
Sources/​App/​Settings/​Settings/​ServersListView.swift Adds the context-menu action and presentation modifier.
Sources/​App/​Settings/​Connection/​ServerReauthenticationModifier.swift Presents authentication steps and errors.
Sources/​App/​Settings/​Connection/​ServerReauthenticationModel.swift Coordinates server-scoped authentication state.
Sources/​App/​Settings/​Connection/​ConnectionSettingsViewModel.swift Keeps the displayed certificate synchronized.
Sources/​App/​Settings/​Connection/​ConnectionSettingsView.swift Adds the re-authentication section and search entry.
Sources/​App/​Resources/​en.lproj/​Localizable.strings Adds English re-authentication labels and guidance.
Sources/​App/​Frontend/​WebView/​WebViewController/​WebViewController+URLLoading.swift Registers for re-authentication notifications.
Sources/​App/​Frontend/​WebView/​WebViewController/​WebViewController+ReAuth.swift Resets authentication state and reloads the frontend.
Sources/​App/​Container/​ServerReauthenticator.swift Extracts reusable server re-authentication logic.
Sources/​App/​Container/​OnboardingStateObservable.swift Delegates recovered-server authentication to the shared helper.
HomeAssistant.xcodeproj/​project.pbxproj Updates membership exceptions for the new settings files.

Review effort: Balanced

Comment on lines +58 to +59
server.update { serverInfo in
serverInfo.token = tokenInfo

model.start(for: server)

#expectawait (waitUntil { controller.presentedViewController != nil })
Comment on lines +23 to +24
.sheet(item: model.certificateRequestBinding(for: server)) {
RecoveredServerClientCertificateImportView(request: $0, asSheet: true)
@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.60%. Comparing base (3ef4355) to head (7495374).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6128      +/-   ##
==========================================
+ Coverage   57.48%   57.60%   +0.12%     
==========================================
  Files        1278     1282       +4     
  Lines       84565    84727     +162     
==========================================
+ Hits        48614    48811     +197     
+ Misses      35951    35916      -35     
Files with missing lines Coverage Δ
...rces/App/Container/OnboardingStateObservable.swift 72.41% <100.00%> (-3.23%) ⬇️
Sources/App/Container/ServerReauthenticator.swift 100.00% <100.00%> (ø)
...w/WebViewController/WebViewController+ReAuth.swift 25.55% <100.00%> (+8.27%) ⬆️
...bViewController/WebViewController+URLLoading.swift 76.22% <100.00%> (+0.50%) ⬆️
.../Connection/ClientCertificateImportFormSheet.swift 100.00% <100.00%> (ø)
...p/Settings/Connection/ConnectionSettingsView.swift 65.01% <100.00%> (+6.22%) ⬆️
...tings/Connection/ConnectionSettingsViewModel.swift 70.13% <100.00%> (+0.10%) ⬆️
...tings/Connection/ServerReauthenticationModel.swift 100.00% <100.00%> (ø)
...gs/Connection/ServerReauthenticationModifier.swift 100.00% <100.00%> (ø)
...ources/App/Settings/Settings/ServersListView.swift 91.86% <100.00%> (+0.50%) ⬆️

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal
bgoncal merged commit 43010e9 into main Oct 25, 2026
19 of 20 checks passed
@bgoncal
bgoncal deleted the reauthenticate-server branch October 25, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants