Latest 2.2.5
Homepage https://github.com/smartcar/ios-sdk
License MIT
Platforms ios 9.0
Authors

Smartcar iOS Auth SDK

CI Status
Version
License
Platform

The SmartcarAuth iOS SDK makes it easy to handle the Smartcar authorization flow from iOS.

The SDK follows the best practices set out in OAuth 2.0 for Native Apps including using SFSafariViewController on iOS for the authorization request. UIWebView is explicitly not supported due to usability and security reasons.

Requirements

SmartcarAuth supports iOS 7 and above.

iOS 9+ uses the in-app browser tab pattern (via SFSafariViewController), and falls back to the system browser (mobile Safari) on earlier versions.

Installation

SmartcarAuth is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SmartcarAuth"

Getting Started

First, you need to have a global SmartcarAuth object in your AppDelegate to hold the session, in order to continue the authorization flow from the redirect.

// global variable in the app's AppDelegate
var smartcarSdk: SmartcarAuth? = nil

Then, initiate the SmartcarAuth object in the UIViewController.

let appDelegate = UIApplication.shared.delegate as! AppDelegate

func completionHandler(err: Error?, code: String?, state: String?) -> Any {
 // Receive authorization code
}

appDelegate.smartcar = SmartcarAuth(
  clientId: "afb0b7d3-807f-4c61-9b04-352e91fe3134",
  redirectUri: "scafb0b7d3-807f-4c61-9b04-352e91fe3134://page",
  scope: ["read_vin", "read_vehicle_info", "read_odometer"],
  completion: completionHandler
)
let smartcar = appDelegate.smartcar

// initialize authorization flow on the SFSafariViewController
smartcar.launchAuthFlow(state: state, forcePrompt: false, testMode: false, viewController: viewController)

Handling the Redirect

The authorization response URL is returned to the app via the iOS openURL app delegate method, so you need to pipe this through to the current authorization session

/**
    Intercepts callback from OAuth SafariView determined by the custom URI
 */
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsLey : Any] = [:]) -> Bool {
    // Close the SFSafariViewController
    window!.rootViewController?.presentedViewController?.dismiss(animated: true , completion: nil)

    // Sends the URL to the current authorization flow (if any) which will
    // process it and then call the completion handler.
    if let sdk = smartcarSdk {
        sdk.handleCallback(url: url)
    }

    // Your additional URL handling (if any) goes here.

    return true
}

SDK Reference

For detailed documentation on parameters and available methods, please refer to
the SDK Reference.

Author

Smartcar Inc., [email protected]

License

SmartcarAuth is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SmartcarAuth",
    "version": "2.2.5",
    "summary": "Smartcar Authentication SDK for iOS written in Swift 3.",
    "description": "Smartcar Authentication SDK for iOS written in Swift 3.n    - Facilitates the flow with a SFSafariViewController to redirect to Smartcar and retrieve an authorization code",
    "homepage": "https://github.com/smartcar/ios-sdk",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "Smartcar Inc.": "[email protected]"
    },
    "source": {
        "git": "https://github.com/smartcar/ios-sdk.git",
        "tag": "v2.2.5"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "SmartcarAuth/**/*.swift",
    "swift_versions": "3.2",
    "swift_version": "3.2"
}

Pin It on Pinterest

Share This