OauthCapture

@objcMembers
@MainActor
public class OauthCapture : NSObject, WKScriptMessageHandler, WKNavigationDelegate
extension OauthCapture: ASWebAuthenticationPresentationContextProviding

Class for the OauthCapture that will launch a webview for the specified auth URL, open an ASWebAuthenticationSession for a specified OEM, and process the redirect from Connect

  • Constructor for OauthCapture

    Declaration

    Swift

    @MainActor
    public init(viewController: UIViewController, authUrl: URL, redirectUriHost: String, handleCallback: @escaping (URL) -> Void)

    Parameters

    viewController

    the UIViewController responsible for presenting Connect

    authUrl

    the Connect URL to open

    redirectUriHost

    host of the redirect URI that was passed to SmartcarAuth

    handleCallback

    callback function from SmartcarAuth that verifies that no error occured during the OAuth process and extracts the auth code, state string, and virtualKeyUrl upon success. Invokes the completion function with either the code or an error (and state and/or virtualKeyUrl if included).

  • Listens to changes in the navigation to determine if the redirect from Connect has happened. If so, call the handleCallback function and close the webview

    Declaration

    Swift

    @MainActor
    public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)
  • Launches the webview to begin the Smartcar Connect flow

    Declaration

    Swift

    @MainActor
    public func launchWebView()
  • Recieves the SmartcarSDK message when the custom JS injected into the webview is called by Connect. Launches the ASWebAuthenticationSession for login with the OEM.

    Declaration

    Swift

    @MainActor
    public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage)
  • Provides a default window to act as the presentation anchor for the authentication session

    Declaration

    Swift

    @MainActor
    public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor