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
OAuthCapturewhich:- Sets up the JS injection (
window.SmartcarSDK.sendMessage) in the provided WKWebView. - Registers itself as the script message handler named “SmartcarSDK”.
Declaration
Swift
@MainActor public init(webView: WKWebView) - Sets up the JS injection (
-
Required delegate function to handle messages posted from JavaScript code (
SmartcarSDK.sendMessage).This will:
- Parse the JSON-RPC request from JS.
- Start the OEM login flow using ASWebAuthenticationSession.
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
View on GitHub