SmartcarAuth
@objcMembers
public class SmartcarAuth : NSObject
extension SmartcarAuth: ASWebAuthenticationPresentationContextProviding
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( clientId: String, redirectUri: String, scope: [String], 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
completion
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 URLDeclaration
Swift
public func authUrlBuilder() -> SCUrlBuilder
-
Starts the launch of Smartcar Connect.
The way that the browser is launched depends on the iOS version:
iOS 10:
SFSafariViewController
iOS 11:
SFAuthenticationSession
iOS 12+:
ASWebAuthenticationSession
If you are supporting iOS 10, you will need to pass in a UIViewController, as well as intercept the callback in your application (see
README
for an example).Declaration
Swift
public func launchAuthFlow(url: String, viewController: UIViewController? = nil)
Parameters
authUrl
the authorization URL for Smartcar Connect. Use
SCURLBuilder
to generate a auth URLviewController
Optional, the view controller responsible for presenting the SFSafariView. Only necessary if the application supports iOS 10 and lower. Defaults to nil.
-
Authorization callback function. 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).
Declaration
Swift
public func handleCallback(callbackUrl: URL)
Parameters
url
callback URL containing authorization code or an error
-
Provides a default window to act as the presentation anchor for the authentication session
Declaration
Swift
public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor