Slide 31
Slide 31 text
LoginViewDataSource
final class LoginViewDataSource: WKNavigationDelegate {
let viewModel: LoginViewModel
init(viewModel: LoginViewModel) {
self.viewModel = viewModel
}
func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
guard let url = navigationAction.request.url else {
decisionHandler(.cancel)
return
}
if url.absoluteString.hasPrefix(Config.shared.redirectUrl) {
guard
let URLComponents = URLComponents(string: url.absoluteString),
// and so on...
let code = codeItem.value
else { fatalError("can not find \"code\" from URL query") }
// viewModel͔ΒAccessTokenΛϦΫΤετ
viewModel.requestAccessToken(withCode: code)
decisionHandler(.cancel)
return
}
decisionHandler(.allow)
}
}