OAuthCapture

@objcMembers
@MainActor
public class OAuthCapture : NSObject, WKScriptMessageHandler
extension OAuthCapture: ASWebAuthenticationPresentationContextProviding

Responsible for:

  • Injecting JavaScript that lets Connect communicate back to the native SDK (via SmartcarSDK.sendMessage).
  • Responding to the JS messages (WKScriptMessageHandler).
  • Starting an ASWebAuthenticationSession for the OEM login flow.
  • Capturing the OEM callback or error, then sending a JS event back to the web context.
  • Creates an instance of OAuthCapture which:

    • Sets up the JS injection (window.SmartcarSDK.sendMessage) in the provided WKWebView.
    • Registers itself as the script message handler named “SmartcarSDK”.
      • onComplete: Callback invoked when Connect sends a complete RPC message (redirect-less flow completion).

    Declaration

    Swift

    @MainActor
    public init(webView: WKWebView, onComplete: @escaping (CompleteParams) -> Void)

    Parameters

    onComplete

    Callback invoked when Connect sends a complete RPC message (redirect-less flow completion).

  • Required delegate function to handle messages posted from JavaScript code (SmartcarSDK.sendMessage).

    Dispatches by JSON-RPC method:

    • complete: a redirect-less Connect flow finished; hand the result to onComplete and ack.
    • oauth: start the OEM login flow using ASWebAuthenticationSession.
    • anything else is dropped, matching the existing try?-swallows-decode-errors behavior.

    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