SmartcarAuth

@objcMembers
public class SmartcarAuth : NSObject

Smartcar Authentication SDK for iOS written in Swift 5. - Facilitates the authorization flow to launch the flow and retrieve an authorization code

  • Constructor for the SmartcarAuth

    Declaration

    Swift

    public init(
        applicationId: String,
        redirectUri: String? = nil,
        scope: [String]? = nil,
        responseType: String = "code",
        completionHandler: @escaping (String?, String?, String?, String?, String?, AuthorizationError?) -> Void,
        mode: SCMode? = nil
    )

    Parameters

    applicationId

    The application’s application ID

    redirectUri

    Optional. The application’s redirect URI. Required when responseType is "code". If required but not specified, uses default set in the Smartcar developer dashboard

    scope

    Optional. An array of authorization scopes. If not specified, fall backs to defaults set in the Smartcar developer dashboard.

    responseType

    Optional, determines whether Connect completes the flow via redirect ("code") or via the complete RPC ("none"). Defaults to "code".

    completionHandler

    Callback function called upon the completion of the Smartcar Connect

    mode

    Optional, determine what mode Smartcar Connect should be launched in. Should be one of .test, .live or .simulated. If none specified, defaults to live mode.

  • Declaration

    Swift

    @available(*, deprecated, renamed: "init(applicationId:redirectUri:scope:responseType:completionHandler:mode:﹚")
    public init(
        applicationId: String,
        redirectUri: String,
        scope: [String]? = nil,
        completionHandler: @escaping (String?, String?, String?, String?, AuthorizationError?) -> Void,
        mode: SCMode? = nil
    )

    Parameters

    applicationId

    The application’s application ID

    redirectUri

    The application’s redirect URI. Must be a valid URI.

    scope

    Optional. An array of authorization scopes. If not specified, fall backs to defaults set in the Smartcar developer dashboard.

    completionHandler

    Callback function called upon the completion of the Smartcar Connect

    mode

    Optional, determine what mode Smartcar Connect should be launched in. Should be one of .test, .live or .simulated. If none specified, defaults to live mode.

  • Declaration

    Swift

    @available(*, deprecated, renamed: "init(applicationId:redirectUri:scope:responseType:completionHandler:mode:﹚")
    public init(
        clientId: String,
        redirectUri: String,
        scope: [String]? = nil,
        completionHandler: @escaping (String?, String?, String?, AuthorizationError?) -> Void,
        testMode: Bool = false,
        mode: SCMode? = nil
    )

    Parameters

    clientId

    The application’s client ID

    redirectUri

    The application’s redirect URI. Must be a valid URI.

    scope

    An array of authorization scopes

    completionHandler

    Callback function called upon the completion of the Smartcar Connect

    testMode

    Deprecated, please use mode instead. Optional, launch the Smartcar auth flow in test mode when set to true. Defaults to false.

    mode

    Optional, determine what mode Smartcar Connect should be launched in. Should be one of .test, .live or .simulated. If none specified, defaults to live mode.

  • Helper method to generate a SCURLBuilder instance, which then can be used (with various setters) to build an auth URL See SCURLBuilder for a full list of query parameters that can be set on the authorization URL

    Declaration

    Swift

    public func authUrlBuilder() -> SCUrlBuilder
  • Starts the launch of Smartcar Connect.

    Declaration

    Swift

    public func launchAuthFlow(url: String, viewController: UIViewController)

    Parameters

    authUrl

    the authorization URL for Smartcar Connect. Use SCURLBuilder to generate a auth URL

    viewController

    The view controller responsible for presenting the Connect flow

  • Authorization callback function. Verifies that no error occurred during the OAuth process and extracts the auth code, state string, virtualKeyUrl, and userId upon success. Invokes the completion function with either the code or an error (and state, virtualKeyUrl, and/or userId if included).

    Declaration

    Swift

    public func handleCallback(callbackUrl: URL)

    Parameters

    url

    callback URL containing authorization code or an error

  • Receives the result of a redirect-less Smartcar Connect flow delivered over the complete JSON-RPC message, and invokes the completion function the same way handleCallback does for the redirect-based flow.

    Declaration

    Swift

    public func receiveDirectResult(params: CompleteParams)

    Parameters

    params

    the parsed complete RPC params