Skip to content

Commit 8605ae7

Browse files
committed
Handle authenticating with site credentials in authenticated web view
1 parent a72255e commit 8605ae7

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

WooCommerce/Classes/Authentication/AuthenticatedWebViewController.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ private extension AuthenticatedWebViewController {
8787
}
8888

8989
func startLoading() {
90-
guard let url = viewModel.initialURL else {
91-
return
92-
}
9390
webView.publisher(for: \.estimatedProgress)
9491
.sink { [weak self] progress in
9592
if progress == 1 {
@@ -102,10 +99,26 @@ private extension AuthenticatedWebViewController {
10299

103100
webView.publisher(for: \.url)
104101
.sink { [weak self] url in
105-
self?.viewModel.handleRedirect(for: url)
102+
if url?.absoluteString.contains(WKWebView.wporgNoncePath) == true {
103+
self?.loadContent()
104+
} else {
105+
self?.viewModel.handleRedirect(for: url)
106+
}
106107
}
107108
.store(in: &subscriptions)
108109

110+
if let wporgCredentials = viewModel.wporgCredentials,
111+
let request = try? webView.authenticateForWPOrg(with: wporgCredentials) {
112+
webView.load(request)
113+
} else {
114+
loadContent()
115+
}
116+
}
117+
118+
private func loadContent() {
119+
guard let url = viewModel.initialURL else {
120+
return
121+
}
109122
if let credentials = ServiceLocator.stores.sessionManager.defaultCredentials {
110123
webView.authenticateForWPComAndRedirect(to: url, credentials: credentials)
111124
} else {

0 commit comments

Comments
 (0)