How to access the authentication code appended to URI query parameters after logging in with WKWebView?

Viewed 38

Trying to authenticate using Teamwork API login flow link

I've loaded my WKWebView and am able to sign in which takes me to the login successful page, now I am trying to get the authentication code in the response in order to authenticate the app. Step 3 in the instructions says there should be a 'code' query parameter appended to the URI on successful login. I'm not sure what that means. Can anyone help me find the code from the response? I've tried using decidePolicyFor WKWebView delegate methods to grab the query parameters but can't see a code. Thank you for any help.

Code so far:

import UIKit
import WebKit

class LoginViewController: UIViewController, WKNavigationDelegate {

let webView = WKWebView()

override func loadView() {
    self.view = webView
}

override func viewDidLoad() {
    super.viewDidLoad()
    
    webView.navigationDelegate = self

    let urlString = "https://www.teamwork.com/launchpad/login?redirect_uri=redacted&client_id=redacted"
    
    if let url = URL(string: urlString) {
        webView.load(URLRequest(url: url))
    }

}



func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {

    decisionHandler(.allow)
}



func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    

    decisionHandler(.allow)
}



}
1 Answers
Related