NoPass™ SDK for iOS

This SDK applies to iOS version 1.0.0.

Initial setup

Before you begin
  1. In your Xcode project directory, create a Podfile, and add your dependencies:
    use_frameworks!
    target 'YourApp' do
      pod 'NoPass-iOS-SDK', :git => 'https://github.com/identite/nopass.sdk.ios.git', :tag => '1.8.1'
    end
      
     CocoaPods provides a podinit command to create a Podfile with smart defaults. You should use it.
  2. Now, you can install dependencies in your project: $pod install.
  3. Make sure to always open the Xcode workspace instead of the project file building your project:
    $ open YourApp.xcworkspace
      
  4. Now you can import your dependencies:
    import NoPassSDK
      
Migrate logic

Migrate business logic (one-time password generation, encryption/decryption, store, network logic, etc.) from the NoPass™ application to the NoPass™ framework.

Remove 3rd party dependency

To achieve better support SDK, replace the 3rd party libraries with native realization.

 

Realm ➔ CoreData

Alamofire ➔ NSURlSession

etc.

 

Some libraries should be added like the source code.

SDK settings logic

Add logic to basic settings SDK like portalURL, apiKEY, apiVersion, etc.
To configure SDK, call the setup method:

NoPassSDK.setSecretKey(AppConfig.API_KEY)
  

Registration

To start the registration flow, pass the encrypted text from QR or DeepLink to NoPassSDK. Use the NoPassRegistrationService for it.

public func startRegistration(result: String, enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool)
  

Parameters:
result—text from QR or DeepLink
enabled2FaMetho——2Fa method that is used on iPhone
isScreenLock—a bool value that determines if biometry or device passcode is switched on

To handle the registration flow, implement NoPassRegistrationDelegate.
 

protocol NoPassRegistrationDelegate {
// Return registration code (if needed)
func registration(code:String ) 
// Handel result of registration flow 
func finishRegistration(result: String?, error: Error?)
}
  

Authentication

To start the authentication, pass the encrypted text from the push notification to NoPassSDK. Use NoPassAuthService for it. To support backward compatibility with iOS NoPass SDK, convert push notification payload using this method.

private func transformedPayload(_data: [AnyHashable: Any]) -> [String: Any]{
    var dictionary = data
    if let workflowValue = data["Workflow"] as? String, let value = Int(workflowValue){
        dictionary["Workflow"] = value
    }
    guard let jsonData = try? JSONSerialization.data(withJSONObject: dictionary, options: [.prettyPrinted]) else {return[:]}
    let jsonStringRepresentation = String(data: jsonData, encoding: .ascii)
    return ["notification": ["data": jsonStringRepresentation]]
}
  

Then, send return value of the function above to the function startAuthFlow to start the authentication.

public func startAuthFlow(data: [AnyHashable : Any], enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool) -> NoPassSDK.NoPassAuthModel?
  

To confirm authentication, call:

public func authorize(enabled2FaMethod: NoPassSDK.BiometricType = .null, isScreenLock: Bool)

To decline authentication, call:

public func decline(type: NoPassSDK.DeclineType, enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool)
  

To handle the authentication flow, implement NoPassAuthServiceDelegate:

public protocol NoPassAuthServiceDelegate : AnyObject {
    func onAuthDataChange(comparisonContent: NoPassSDK.NoPassAuthComparisonContent, authExparedDate: Date, nextUpdate: TimeInterval)
    func onRadiusAuthStart(clientName: String, account: NoPassSDK.NoPassAccount, authExparedDate: Date)
    func onAuthFinish(error: NoPassSDK.NopassError?, authStatus: NoPassSDK.AuthStatus)
}  
Other methods

To check an active authentication session:

public func isHaveAuthSessionNow() -> Bool
  

To get authentication comparison content:

public func getAuthComparisonContent(data: [String : Any], userSeed: String) -> NoPassSDK.NoPassAuthComparisonContent?

Push notifications

NoPass™ uses the Firebase cloud messaging system in its registration and authorization flows.

  1. For correct work of the registration/authorization flow, pass data from incoming push notification to SDK:
    NoPassNotificationService.shared.setRegistrationToken(token: fcmToken)
      
  2. To handle the push data, you must call the passNotification  method.
    public func passNotification(data: [AnyHashable : Any]?, enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool)
      
  3. To get the notification from NoPass™, type:
    extension AppDelegate: MessagingDelegate {
        func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    NoPassNotificationService.shared.setRegistrationToken(token: fcmToken)
        }
    func application(
      _ application: UIApplication,
      didReceiveRemoteNotification userInfo: [AnyHashable : Any],
      fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult)->Void
    ) {
      guard let data = userInfo as? [String: Any] else { return }
          NoPassNotificationService.shared.passNotification(data: data,
          enabled2FaMethod: LocalAuthService.biometricType(),
          isScreenLock: LocalAuthService.isSceenLock()
      )
      completionHandler(.newData)    
    }
    

Other operations

There are other operations that can be performed with the account service manager. You must use NoPassAccountService.

  1. Get the list of all users:
    NoPassAccountService.shared.fetchAccounts()
      
  2. Get the authentication history:
    NoPassAccountService.shared.fetchHisory()
      
  3. You can also delete the user from both back-end and the mobile device:
    public func removeAccount(account: NoPassSDK.NoPassAccount, enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool, completion: ((NSError?) -> Void)?)
     
  4. To subscribe on accounts changing action, you must call:
    NoPassAccountService.shared.subscribe()
     
    And set up closure:
    NoPassAccountService.shared.onAccountsChange = { [weak self] in
                // some logic for updating UI         
            }
      
  5. Backup. It is also possible to create a backup data string encrypted by a 6-digits pin-code. This data may be used to restore accounts later. To unitiate backup, do the following:
    // encryptedBackupData - existed backup data
    public func backupAccounts(pin: String, encryptedBackupData: String?, enabled2FaMethod: NoPassSDK.BiometricType, isSreenLock: Bool, completion: ((NoPassSDK.NopassError?, String?) -> Void)?)
      
  6. Restore. If there are properly backed up accounts, they can be restored by a backup string and the pin code. To begin restoration, run the following command:
    // restoreDidStart closure returns a count of backup accounts and NopassError
    public func restoreAccounts(backupData: String, pin: String, delegate: NoPassSDK.RestoreFlowDelegate?, enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool, restoreDidStart: ((Int, NoPassSDK.NopassError?) -> Void)?)
      
  7. To remove backup data:
    public func clearBackupData()
      
  8. To check if file can be decoded:
    public func isCanDecodeBackupFile(encodedString: String, pin: String) -> Bool
      
  9. To start the synchronization flow, pass the encrypted text from QR to NoPassSDK. You must use NoPassSynchronisationService.
    public func startSyncAccount(result: String, enabled2FaMethod: NoPassSDK.BiometricType, isScreenLock: Bool)
    
  10. To handle the synchronization flow, implement NoPassSynchronisationServiceDelegate:
    public protocol NoPassSynchronisationServiceDelegate : AnyObject {
        func synchronisationDidFinish()
        func syncRegistrationCode(code: String, isNeedConfirmationCode: Bool)
        func accountWasSynchronised(account: NoPassSDK.NoPassAccount?, error: NoPassSDK.NopassError?)
        func synchronisationDidFail(error: NoPassSDK.NopassError)
    }
    

 

next topic: Licensing

previous topic: NoPass™ SDK for React

Suggest edits