Acceptto eGuardian™ Framework


Acceptto eGuardian™ Framework can be used for Device Registration and Association with User Identity, Behaviour Based Analytics, Biometric Authentication, Multi Factor Authentication/Authorization, Single Sign out, Remote Session Management, Authorization Notification and History.

Integerate for enable location tracking


add this 2 keys to info.plist to your subproject


<key>NSLocationWhenInUseUsageDescription</key>
<string>This application requires location services to work</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>This application requires location services to work</string>
  • Enable location from Cababilites / Background Mode
  • add (copy) Meta.sqlite to bundle of sub project

Adding eGuardian™ to a new project


First of all you need to have CocoaPods installed on your system:

$ sudo gem install cocoapods

Then go to the root of your project and type:

$ pod init

Then open the create Podfile and replace the content with these lines:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'Alamofire', '~> 3.0'
pod 'UrbanAirship-iOS-SDK/All'
pod 'HockeySDK'
pod 'ISO8601DateFormatter'

This podfile added HockeySDK and assumes that you are using HockeyApp for test and beta testing. otherwise you can remove it safely.

Now you can open the created *.xcworkspace always make sure to open this workspace of file instead of xcodeproj file, otherwise you will get compile/build errors.

Then open up XCode and add these frameworks to your Linked Framework and Binaries and Embeded Binaries (In General section of Target settings):

  • LocalAuthentication.framework (which belongs to Apple and is used for TouchID authentication)
  • AccepttoEguardianFramework.framework (Acceptto eGuardian SDK)

Now you can work on actual implementation of eGuardian SDK.

User Registration

Checkout the documentation of User#register. This method regsiters registers a new user on Acceptto backend also generates eGuardian unique identifiers and keys on Keychain of device and locks current device for current user, So nobody else can sign in on this device.

Sign In

Checkout the documentation of User#signIn. This method only works if user already registered on this device.

Single Sign Out (Remote Session Kill)

Checkout the documentation of User#singleSignOut. Thie method kills all the Single Sign On remote sessions for user. for example if user signed in on any other device or website this method will expire those sessions.

TouchID and Security Validation

Checkout the documentation of User#touchIdAndSecurityValidation This is the wrapper for Acceptto Device Identity check. You can use this method to authorize user for an action So this is the method to authenticate the user locally with touch ID and then execute the corresponding request.

Get Current User Data

Checkout the documentation of User#getUserData. Loads last registered user data on this device from keychain and Acceptto backend.

History (List of last 10 Authorization/Authentication requests)

Checkout the documentation of Authorization#getListOfAuthorizations. This method finds list of authorizations for current user active on current device.

Find One Authorization

Checkout the documentation of Authorization#findAuthorization. This method Finds authorization by one time password for current active user on device. This is used when a push notification comes to your application which containts an OTP (One Time Password). You can use this method to load authorization request details by provided otp.

Reply to Authorization Request (Accept/Decline)

Checkout the documentation of Authorization#reply. This method replies to authorization request with approved or rejected. Authorization must belong to current active user on current device.

Request to add another device to list of authorized devices

Checkout the documentation of User#registerAnotherDevice. This method creates a request for adding another device to list of active authorized devices of user. This API call generates a one time password and device identifier for new device. iOS application can use this parameters to create a comma seperated string which is needed for confirm new device method User#confirmThisDevice

Confirm new device

Checkout the documentation of User#confirmThisDevice. This method confirms second device and add it to list of active devices for user. input is the QR Code string which is a comma seperated string with this format: member_id,device_id,otp. If confrim succeeds you can safely call User#signIn on new device and user gets logged in.

Registering for push notification


In order to register for push notifications on iOS and Apple Watch you should get your appKey and appSecret from Acceptto. Here is a sample implementation on AppDelegate:

import UIKit
import AirshipKit
import HockeySDK
import AccepttoEGuardianFramework


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var currentNavigationController : UINavigationController?
    var signedIn : Bool?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        var appKey = "your_acceptto_push_app_key"
        var appSecret = "your_acceptto_push_app_secret"        
        PushNotificationHelpers.loadPushSettings(appKey, appSecret: appSecret, inProduction: inProduction)
        loadHockeyManager()
        return true
    }

    /**
     Registering and starting hockey app manager for crash report and auto updates
    */
    func loadHockeyManager() {
        BITHockeyManager.sharedHockeyManager().configureWithIdentifier("your_hockey_app_identifier");
        BITHockeyManager.sharedHockeyManager().crashManager.crashManagerStatus = BITCrashManagerStatus.AutoSend
        BITHockeyManager.sharedHockeyManager().crashManager.enableAppNotTerminatingCleanlyDetection = true
        BITHockeyManager.sharedHockeyManager().startManager();
        BITHockeyManager.sharedHockeyManager().authenticator.authenticateInstallation();
    }

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        PushNotificationHelpers.didRegisterForRemoteNotification(deviceToken)
    }

    func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
        PushNotificationHelpers.didRegisterUserNotificationSettings(notificationSettings)
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    // handles interactive push actions when user clicks on accept or decline button on push notification
    func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler: () -> Void) {

        if (self.signedIn == nil || self.signedIn == false) {
            completionHandler()
            return
        }

        PushNotificationHelpers.application(application, handleActionWithIdentifier: identifier, forRemoteNotification: userInfo, env: Consts.Environment, completionHandler: completionHandler)
    }

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        if (self.signedIn == nil || self.signedIn == false) {
            completionHandler(.NoData)
            return
        }

        if (self.currentNavigationController != nil) {
            PushNotificationHelpers.application(application, didReceiveRemoteNotification: userInfo, env: Consts.Environment, fetchCompletionHandler: completionHandler, loadAuthorizationView: loadAuthorizationView, showError: showError)
        }
        else {
            completionHandler(.NoData)
        }
    }

    // When push notification comes this will load authorization detail view and user can accept/decline authorization request
    func loadAuthorizationView(auth: Authorization) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc : AuthorizationDetailTableViewController = storyboard.instantiateViewControllerWithIdentifier("authorizationDetailViewController") as! AuthorizationDetailTableViewController
        vc.auth = auth
        currentNavigationController!.showViewController(vc, sender: self)
    }

    // If load of push notification fails for some reason this method will be called back to show the error message to user or log it somewhere
    func showError(message: String?) {
        dispatch_async(dispatch_get_main_queue()) {
            let alertController = UIAlertController(title: "Error", message:
                "", preferredStyle: UIAlertControllerStyle.Alert)

            alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))

            alertController.message = message;

            self.currentNavigationController!.presentViewController(alertController, animated: true, completion: nil)
        }

    }
}