mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-17 08:05:44 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> This PR adds experimental mTLS support, it does not work properly on older iOS versions neither on Apple Watch yet. Mac Catalyst TBD how well it works. This PR modifies: - WebView connection - Alamofire token exchange - Webhook - Websocket (pending HAKit PR) Pending implementation/check - [ ] Apple Watch - [ ] Background usage (widgets, shortcuts, notifications) - [x] Mac Catalyst - [ ] Background refresh - [x] [HAKit PR](https://github.com/home-assistant/HAKit/pull/92/changes#diff-1ccd1173574d21603ee9aab6340ee5c825e62b94f112362346a931b10463594b) ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> Happy path: https://github.com/user-attachments/assets/8d41d871-8cb8-4498-8e09-24716fff6971 ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
57 lines
1.9 KiB
Swift
57 lines
1.9 KiB
Swift
import Foundation
|
|
import Shared
|
|
|
|
class OnboardingAuthDetails: Equatable {
|
|
var url: URL
|
|
var scheme: String
|
|
var exceptions: SecurityExceptions = .init()
|
|
var clientCertificate: ClientCertificate?
|
|
|
|
init(baseURL: URL) throws {
|
|
guard var components = URLComponents(url: baseURL.sanitized(), resolvingAgainstBaseURL: false) else {
|
|
throw OnboardingAuthError(kind: .invalidURL)
|
|
}
|
|
|
|
let redirectURI: String
|
|
let scheme: String
|
|
let clientID: String
|
|
|
|
// swiftlint:disable prohibit_environment_assignment
|
|
if Current.appConfiguration == .debug {
|
|
clientID = "https://home-assistant.io/iOS/dev-auth"
|
|
redirectURI = "homeassistant-dev://auth-callback"
|
|
scheme = "homeassistant-dev"
|
|
} else if Current.appConfiguration == .beta {
|
|
clientID = "https://home-assistant.io/iOS/beta-auth"
|
|
redirectURI = "homeassistant-beta://auth-callback"
|
|
scheme = "homeassistant-beta"
|
|
} else {
|
|
clientID = "https://home-assistant.io/iOS"
|
|
redirectURI = "homeassistant://auth-callback"
|
|
scheme = "homeassistant"
|
|
}
|
|
// swiftlint:enable prohibit_environment_assignment
|
|
|
|
components.path += "/auth/authorize"
|
|
components.queryItems = [
|
|
URLQueryItem(name: "response_type", value: "code"),
|
|
URLQueryItem(name: "client_id", value: clientID),
|
|
URLQueryItem(name: "redirect_uri", value: redirectURI),
|
|
]
|
|
|
|
guard let authURL = components.url else {
|
|
throw OnboardingAuthError(kind: .invalidURL)
|
|
}
|
|
|
|
self.url = authURL
|
|
self.scheme = scheme
|
|
}
|
|
|
|
static func == (lhs: OnboardingAuthDetails, rhs: OnboardingAuthDetails) -> Bool {
|
|
lhs.url == rhs.url &&
|
|
lhs.scheme == rhs.scheme &&
|
|
lhs.exceptions == rhs.exceptions &&
|
|
lhs.clientCertificate == rhs.clientCertificate
|
|
}
|
|
}
|