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, scope: [String]? = nil, completionHandler: @escaping (String?, String?, String?, String?, AuthorizationError?) -> Void, mode: SCMode? = nil )Parameters
applicationIdThe application’s application ID
redirectUriOptional. The application’s redirect URI. If not specified, uses default set in the Smartcar developer dashboard.
scopeOptional. An array of authorization scopes. If not specified, fall backs to defaults set in the Smartcar developer dashboard.
completionHandlerCallback function called upon the completion of the Smartcar Connect
modeOptional, determine what mode Smartcar Connect should be launched in. Should be one of .test, .live or .simulated. If none specified, defaults to live mode.
-
Deprecated. Use
init(applicationId:redirectUri:scope:completionHandler:mode:)instead.Declaration
Swift
@available(*, deprecated, renamed: "init(applicationId:redirectUri:scope: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
clientIdThe application’s client ID
redirectUriThe application’s redirect URI. Must be a valid URI.
scopeAn array of authorization scopes
completionHandlerCallback function called upon the completion of the Smartcar Connect
testModeDeprecated, please use
modeinstead. Optional, launch the Smartcar auth flow in test mode when set to true. Defaults to false.modeOptional, 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
SCURLBuilderfor a full list of query parameters that can be set on the authorization URLDeclaration
Swift
public func authUrlBuilder() -> SCUrlBuilder -
Starts the launch of Smartcar Connect.
Declaration
Swift
public func launchAuthFlow(url: String, viewController: UIViewController)Parameters
authUrlthe authorization URL for Smartcar Connect. Use
SCURLBuilderto generate a auth URLviewControllerThe 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
urlcallback URL containing authorization code or an error
View on GitHub