From a0908eb9e73c340480cffd7eb0410cf5e0f9e393 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Wed, 13 Feb 2019 17:17:06 +0530 Subject: [PATCH 01/14] Face Recognition API changes and Touch ID enabled in SDK --- Cidaas.podspec | 2 +- .../Face/FaceVerificationController.swift | 4 +- .../Core/Helpers/Biometrics/TouchID.swift | 92 +++++++++++++++++++ .../Core/Helpers/Enums/WebAuthErrorCode.swift | 11 +++ .../Core/Helpers/General/URLHelper.swift | 4 +- .../Verification/Face/EnrollFaceEntity.swift | 1 + .../Face/EnrollFaceResponseEntity.swift | 24 +++++ Cidaas/Classes/Core/Views/Cidaas.swift | 37 +++++++- Cidaas/Classes/Core/Views/CidaasView.swift | 3 +- Example/Cidaas/Info.plist | 2 + Example/Cidaas/ViewController.swift | 56 ++++++----- Example/Tests/TouchIdTests.swift | 4 +- 12 files changed, 206 insertions(+), 34 deletions(-) create mode 100644 Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift diff --git a/Cidaas.podspec b/Cidaas.podspec index 064269b..50ea220 100644 --- a/Cidaas.podspec +++ b/Cidaas.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'Cidaas' - s.version = '1.1.2' + s.version = '1.1.3' s.summary = 'Native SDK for iOS providing login, registration and verification functionalities' s.homepage = 'https://github.com/Cidaas/cidaas-sdk-ios-v2' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift b/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift index b935e16..f5d78ce 100644 --- a/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift +++ b/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift @@ -300,9 +300,9 @@ public class FaceVerificationController { } // validating fields - if (enrollFaceEntity.statusId == "" || enrollFaceEntity.userDeviceId == "") { + if (enrollFaceEntity.statusId == "" || enrollFaceEntity.userDeviceId == "" || enrollFaceEntity.attempt == 0) { let error = WebAuthError.shared.propertyMissingException() - error.errorMessage = "statusId or userDeviceId must not be empty" + error.errorMessage = "statusId or userDeviceId or attempt must not be empty" DispatchQueue.main.async { callback(Result.failure(error: error)) } diff --git a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift new file mode 100644 index 0000000..65e460e --- /dev/null +++ b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift @@ -0,0 +1,92 @@ +// +// TouchID.swift +// Cidaas +// +// Created by ganesh on 13/02/19. +// + +import Foundation +import LocalAuthentication + +public class TouchID { + + public static let sharedInstance = TouchID() + let authenticatedContext = LAContext() + var error: NSError? + + public func checkIfTouchIdAvailable(callback: @escaping (Bool, String?, Int32?)->()) { + if authenticatedContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) { + DispatchQueue.main.async { + callback(true, nil, nil) + } + } + else { + switch error!.code { + case LAError.touchIDNotAvailable.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not available", WebAuthErrorCode.TOUCHID_NOT_AVAILABLE.rawValue) + } + break + case LAError.touchIDNotEnrolled.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not enrolled", WebAuthErrorCode.TOUCHID_NOT_ENROLLED.rawValue) + } + break + case LAError.passcodeNotSet.rawValue: + DispatchQueue.main.async { + callback(false, "Passcode not configured", WebAuthErrorCode.PASSCODE_NOT_CONFIGURED.rawValue) + } + break + case LAError.authenticationFailed.rawValue: + DispatchQueue.main.async { + callback(false, "Invalid authentication", WebAuthErrorCode.INVALID_AUTHENTICATION.rawValue) + } + break + case LAError.appCancel.rawValue: + DispatchQueue.main.async { + callback(false, "App cancelled", WebAuthErrorCode.APP_CANCELLED.rawValue) + } + break + case LAError.systemCancel.rawValue: + DispatchQueue.main.async { + callback(false, "System cancelled", WebAuthErrorCode.SYSTEM_CANCELLED.rawValue) + } + break + case LAError.userCancel.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.USER_CANCELLED.rawValue) + } + break + case LAError.touchIDLockout.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId locked", WebAuthErrorCode.TOUCHID_LOCKED.rawValue) + } + break + case LAError.userFallback.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.USER_CANCELLED.rawValue) + } + break + default: + DispatchQueue.main.async { + callback(false, "Error occured", WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + } + break + } + } + } + + public func checkTouchIDMatching(localizedReason: String, callback: @escaping (Bool, String?, Int32?)->()) { + authenticatedContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: localizedReason, reply: { (success, error) -> Void in + if( success ) { + DispatchQueue.main.async { + callback(true, nil, nil) + } + }else { + DispatchQueue.main.async { + callback(false, error?.localizedDescription, WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + } + } + }) + } +} diff --git a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift index 463693a..83ad548 100644 --- a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift +++ b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift @@ -212,4 +212,15 @@ public enum WebAuthErrorCode : Int32 { case DENY_REQUEST_SERVICE_FAILURE = 10175 case UPDATE_FCM_SERVICE_FAILURE = 10176 case PENDING_NOTIFICATION_LIST_SERVICE_FAILURE = 10177 + + case TOUCHID_NOT_AVAILABLE = 10178 + case TOUCHID_NOT_ENROLLED = 10179 + case PASSCODE_NOT_CONFIGURED = 10180 + case INVALID_AUTHENTICATION = 10181 + case APP_CANCELLED = 10182 + case SYSTEM_CANCELLED = 10183 + case USER_CANCELLED = 10184 + case TOUCHID_LOCKED = 10185 + case TOUCHID_DEFAULT_ERROR = 10186 + } diff --git a/Cidaas/Classes/Core/Helpers/General/URLHelper.swift b/Cidaas/Classes/Core/Helpers/General/URLHelper.swift index c99e39d..e1046d1 100644 --- a/Cidaas/Classes/Core/Helpers/General/URLHelper.swift +++ b/Cidaas/Classes/Core/Helpers/General/URLHelper.swift @@ -169,8 +169,8 @@ public class URLHelper { return loginWithCredentialsURL } - public func getLogoutURL() -> String { - return logoutURL + public func getLogoutURL(accessToken: String) -> String { + return logoutURL + "?access_token_hint=" + accessToken } public func getConsentURL(consent_name: String, version: Int16) -> String { diff --git a/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceEntity.swift b/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceEntity.swift index fbf9660..d0e2532 100644 --- a/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceEntity.swift +++ b/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceEntity.swift @@ -14,6 +14,7 @@ public class EnrollFaceEntity : Codable { public var userDeviceId: String = "" public var usage_pass: String = "" public var client_id: String = "" + public var attempt: Int32 = 0 public var deviceInfo: DeviceInfoModel = DeviceInfoModel() // Constructors diff --git a/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceResponseEntity.swift b/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceResponseEntity.swift index efab42a..012309d 100644 --- a/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceResponseEntity.swift +++ b/Cidaas/Classes/Core/Services/Entity/Verification/Face/EnrollFaceResponseEntity.swift @@ -33,6 +33,8 @@ public class EnrollFaceResponseDataEntity : Codable { public var trackingCode: String = "" public var verificationType: String = "" public var usageType: String = "" + public var enrolled: Bool? + public var meta: EnrollFaceResponseMetaData? // Constructors public init() { @@ -46,5 +48,27 @@ public class EnrollFaceResponseDataEntity : Codable { self.trackingCode = try container.decodeIfPresent(String.self, forKey: .trackingCode) ?? "" self.verificationType = try container.decodeIfPresent(String.self, forKey: .verificationType) ?? "" self.usageType = try container.decodeIfPresent(String.self, forKey: .usageType) ?? "" + self.enrolled = try container.decodeIfPresent(Bool.self, forKey: .enrolled) + self.meta = try container.decodeIfPresent(EnrollFaceResponseMetaData.self, forKey: .meta) + } +} + +public class EnrollFaceResponseMetaData : Codable { + + // properties + public var comment: String? + public var number_images_needed: Int32? + public var number_images_uploaded: Int32? + + // Constructors + public init() { + + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.comment = try container.decodeIfPresent(String.self, forKey: .comment) + self.number_images_needed = try container.decodeIfPresent(Int32.self, forKey: .number_images_needed) + self.number_images_uploaded = try container.decodeIfPresent(Int32.self, forKey: .number_images_uploaded) } } diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index ef3f526..09f7ba2 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -1119,11 +1119,44 @@ public class Cidaas { // 2. Call configureTouchId method // 3. Maintain logs based on flags - public func configureTouchId(sub: String, logoUrl: String, callback: @escaping(Result) -> Void) { + public func configureTouchId(sub: String, logoUrl: String, localizedReason: String, callback: @escaping(Result) -> Void) { let savedProp = DBHelper.shared.getPropertyFile() if (savedProp != nil) { - TouchIdVerificationController.shared.configureTouchId(sub: sub, logoUrl: logoUrl, properties: savedProp!, callback: callback) + + // ask for touch id or face id + let touchId = TouchID() + touchId.checkIfTouchIdAvailable { (success, errorMessage, errorCode) in + if success == true { + touchId.checkTouchIDMatching(localizedReason: localizedReason, callback: { (res_success, res_errorMessage, res_errorCode) in + if res_success == true { + TouchIdVerificationController.shared.configureTouchId(sub: sub, logoUrl: logoUrl, properties: savedProp!, callback: callback) + } + else { + let error = WebAuthError.shared + error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + }) + } + else { + let error = WebAuthError.shared + error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + } } else { // log error diff --git a/Cidaas/Classes/Core/Views/CidaasView.swift b/Cidaas/Classes/Core/Views/CidaasView.swift index bb81b51..049f336 100644 --- a/Cidaas/Classes/Core/Views/CidaasView.swift +++ b/Cidaas/Classes/Core/Views/CidaasView.swift @@ -373,8 +373,9 @@ public class CidaasView: UIView, WKNavigationDelegate { let savedProp = DBHelper.shared.getPropertyFile() if savedProp != nil { let baseURL = savedProp!["DomainURL"] ?? "" - let logoutURLString = baseURL + URLHelper.shared.getLogoutURL() + let logoutURLString = baseURL + URLHelper.shared.getLogoutURL(accessToken: accessToken) let logoutURL = URLRequest(url: URL(string: logoutURLString)!) + wkWebView.isHidden = false wkWebView.load(logoutURL) } } diff --git a/Example/Cidaas/Info.plist b/Example/Cidaas/Info.plist index f9f7822..82c8110 100644 --- a/Example/Cidaas/Info.plist +++ b/Example/Cidaas/Info.plist @@ -2,6 +2,8 @@ + NSFaceIDUsageDescription + Face Id CFBundleDevelopmentRegion en CFBundleDisplayName diff --git a/Example/Cidaas/ViewController.swift b/Example/Cidaas/ViewController.swift index cff6596..8b2bbfe 100644 --- a/Example/Cidaas/ViewController.swift +++ b/Example/Cidaas/ViewController.swift @@ -9,10 +9,13 @@ import UIKit import Cidaas import WebKit +import LocalAuthentication class ViewController: UIViewController, WKNavigationDelegate, CidaasLoaderDelegate { var cidaas = Cidaas.shared + let authenticatedContext = LAContext() + var error: NSError? @IBOutlet var cidaasView: CidaasView! @@ -27,30 +30,31 @@ class ViewController: UIViewController, WKNavigationDelegate, CidaasLoaderDelega CidaasFacebook.shared.delegate = self CidaasGoogle.shared.delegate = self - cidaasView.loginWithEmbeddedBrowser(delegate: self) { - switch $0 { - case .success(let result): - let alert = UIAlertController(title: "Alert", message: result.data.access_token, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in - switch action.style{ - case .default: - print("default") - - case .cancel: - print("cancel") - - case .destructive: - print("destructive") - }})) - self.present(alert, animated: true, completion: nil) - break - case .failure(let errorResponse): - print(errorResponse.errorMessage) - - break - } - } - +// cidaasView.loginWithEmbeddedBrowser(delegate: self) { +// switch $0 { +// case .success(let result): +// let alert = UIAlertController(title: "Alert", message: result.data.access_token, preferredStyle: .alert) +// alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in +// switch action.style{ +// case .default: +// print("default") +// self.logout(accessToken: result.data.access_token) +// case .cancel: +// print("cancel") +// +// case .destructive: +// print("destructive") +// }})) +// self.present(alert, animated: true, completion: nil) +// +// break +// case .failure(let errorResponse): +// print(errorResponse.errorMessage) +// +// break +// } +// } + // let gl = CidaasGoogle.shared // gl.login(viewType: "login") { // switch $0 { @@ -82,6 +86,10 @@ class ViewController: UIViewController, WKNavigationDelegate, CidaasLoaderDelega } } + func logout(accessToken: String) { + cidaasView.logout(accessToken: accessToken) + } + func hideLoader() { CustomLoader.shared.hideLoader(self.view) } diff --git a/Example/Tests/TouchIdTests.swift b/Example/Tests/TouchIdTests.swift index b51422b..4de3bf1 100644 --- a/Example/Tests/TouchIdTests.swift +++ b/Example/Tests/TouchIdTests.swift @@ -20,7 +20,7 @@ class TouchIdTests: QuickSpec { it("call configure TouchIdRecognition from public") { - cidaas.configureTouchId(sub: "87267324", logoUrl: "askdjhas") { + cidaas.configureTouchId(sub: "87267324", logoUrl: "askdjhas", localizedReason: "Place your finger on your fingerprint sensor") { switch $0 { case .failure(let error): print(error.errorMessage) @@ -34,7 +34,7 @@ class TouchIdTests: QuickSpec { DBHelper.shared.userDefaults.removeObject(forKey: "OAuthProperty") - cidaas.configureTouchId(sub: "87267324", logoUrl: "askdjhas") { + cidaas.configureTouchId(sub: "87267324", logoUrl: "askdjhas", localizedReason: "Place your fingerprint on your fingerprint sensor") { switch $0 { case .failure(let error): print(error.errorMessage) From aa4bc752e876786c03cde2ddfb149e36cb194203 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Thu, 14 Feb 2019 12:22:20 +0530 Subject: [PATCH 02/14] fixes --- .../Face/FaceVerificationController.swift | 29 +++++++++---------- Cidaas/Classes/Core/Views/Cidaas.swift | 7 +++-- Example/Tests/FaceTests.swift | 18 ++++++------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift b/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift index f5d78ce..279aacf 100644 --- a/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift +++ b/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift @@ -29,7 +29,7 @@ public class FaceVerificationController { } // configure Face from properties - public func configureFace(sub: String, photo: UIImage, logoUrl: String, intermediate_id: String = "", properties: Dictionary, callback: @escaping(Result) -> Void) { + public func configureFace(sub: String, photo: UIImage, logoUrl: String, attempt: Int32, intermediate_id: String = "", properties: Dictionary, callback: @escaping(Result) -> Void) { // null check if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil { let error = WebAuthError.shared.propertyMissingException() @@ -66,6 +66,18 @@ public class FaceVerificationController { let loggerMessage = "Access Token success : " + "Access Token - " + String(describing: tokenResponse.data.access_token) logw(loggerMessage, cname: "cidaas-sdk-success-log") + + // if attempt > 1 call enroll + if attempt > 1 { + let enrollFaceEntity = EnrollFaceEntity() + enrollFaceEntity.statusId = self.statusId + + // call enroll service + FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback) + return + } + + // construct object var setupFaceEntity = SetupFaceEntity() setupFaceEntity.logoUrl = logoUrl @@ -132,20 +144,7 @@ public class FaceVerificationController { enrollFaceEntity.statusId = self.statusId // call enroll service - FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties) { - switch $0 { - case .failure(let error): - // return failure callback - DispatchQueue.main.async { - callback(Result.failure(error: error)) - } - return - case .success(let enrollResponse): - DispatchQueue.main.async { - callback(Result.success(result: enrollResponse)) - } - } - } + FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback) break case .failure(let error): diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index 09f7ba2..46efa41 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -1225,11 +1225,11 @@ public class Cidaas { // 2. Call configureFace method // 3. Maintain logs based on flags - public func configureFaceRecognition(photo: UIImage, sub: String, logoUrl: String, callback: @escaping(Result) -> Void) { + public func configureFaceRecognition(photo: UIImage, sub: String, logoUrl: String, attempt: Int32, callback: @escaping(Result) -> Void) { let savedProp = DBHelper.shared.getPropertyFile() if (savedProp != nil) { - FaceVerificationController.shared.configureFace(sub: sub, photo:photo, logoUrl: logoUrl, properties: savedProp!, callback: callback) + FaceVerificationController.shared.configureFace(sub: sub, photo:photo, logoUrl: logoUrl, attempt: attempt, properties: savedProp!, callback: callback) } else { // log error @@ -2034,12 +2034,13 @@ public class Cidaas { // 2. Call enrollTouch method // 3. Maintain logs based on flags - public func enrollFaceRecognition(sub: String, photo: UIImage, statusId: String, callback: @escaping(Result) -> Void) { + public func enrollFaceRecognition(sub: String, photo: UIImage, statusId: String, attempt: Int32, callback: @escaping(Result) -> Void) { let savedProp = DBHelper.shared.getPropertyFile() if (savedProp != nil) { let enrollFaceEntity = EnrollFaceEntity() enrollFaceEntity.statusId = statusId + enrollFaceEntity.attempt = attempt FaceVerificationController.shared.enrollFaceRecognition(sub: sub, access_token: "", photo: photo, enrollFaceEntity: enrollFaceEntity, properties: savedProp!, callback: callback) } diff --git a/Example/Tests/FaceTests.swift b/Example/Tests/FaceTests.swift index 1d030df..52e7dd2 100644 --- a/Example/Tests/FaceTests.swift +++ b/Example/Tests/FaceTests.swift @@ -22,7 +22,7 @@ class FaceTests: QuickSpec { it("call configure FaceRecognition from public") { - cidaas.configureFaceRecognition(photo: UIImage(named: "conflictuser")!, sub: "87267324", logoUrl: "asdkashdjasd") { + cidaas.configureFaceRecognition(photo: UIImage(named: "conflictuser")!, sub: "87267324", logoUrl: "asdkashdjasd", attempt: 1) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -36,7 +36,7 @@ class FaceTests: QuickSpec { DBHelper.shared.userDefaults.removeObject(forKey: "OAuthProperty") - cidaas.configureFaceRecognition(photo: UIImage(named: "conflictuser")!, sub: "87267324", logoUrl: "asdkashdjasd") { + cidaas.configureFaceRecognition(photo: UIImage(named: "conflictuser")!, sub: "87267324", logoUrl: "asdkashdjasd", attempt: 1) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -162,7 +162,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", intermediate_id: "asdasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, intermediate_id: "asdasd", properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -230,7 +230,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -327,7 +327,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", intermediate_id: "asdasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, intermediate_id: "asdasd", properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -453,7 +453,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", intermediate_id: "asdasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, intermediate_id: "asdasd", properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -609,7 +609,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", intermediate_id: "asdasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, intermediate_id: "asdasd", properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -669,7 +669,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) @@ -727,7 +727,7 @@ class FaceTests: QuickSpec { Cidaas.intermediate_verifiation_id = "asdasd" - controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", properties: properties!) { + controller.configureFace(sub: "kajshjasd", photo: UIImage(named: "tick")!, logoUrl: "asdkashdjasd", attempt: 1, properties: properties!) { switch $0 { case .failure(let error): print(error.errorMessage) From 0a96d2948dac538079373f934636f032bdb411c5 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Thu, 14 Feb 2019 14:49:49 +0530 Subject: [PATCH 03/14] enroll face fixes --- .../Verification/Face/FaceVerificationController.swift | 9 ++++++--- .../Verification/Face/FaceVerificationService.swift | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift b/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift index 279aacf..e0a5bbd 100644 --- a/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift +++ b/Cidaas/Classes/Core/Controllers/Repository/Verification/Face/FaceVerificationController.swift @@ -71,6 +71,7 @@ public class FaceVerificationController { if attempt > 1 { let enrollFaceEntity = EnrollFaceEntity() enrollFaceEntity.statusId = self.statusId + enrollFaceEntity.attempt = attempt // call enroll service FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback) @@ -142,6 +143,7 @@ public class FaceVerificationController { let enrollFaceEntity = EnrollFaceEntity() enrollFaceEntity.statusId = self.statusId + enrollFaceEntity.attempt = attempt // call enroll service FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback) @@ -386,11 +388,12 @@ public class FaceVerificationController { timer.invalidate() // construct object - let enrollFaceEntity = EnrollFaceEntity() - enrollFaceEntity.usage_pass = Cidaas.intermediate_verifiation_id + let enrollFaceUsageEntity = EnrollFaceEntity() + enrollFaceUsageEntity.usage_pass = Cidaas.intermediate_verifiation_id + enrollFaceUsageEntity.attempt = enrollFaceEntity.attempt // call enroll service - FaceVerificationService.shared.enrollFace(accessToken:access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties) { + FaceVerificationService.shared.enrollFace(accessToken:access_token, photo: photo, enrollFaceEntity: enrollFaceUsageEntity, properties: properties) { switch $0 { case .failure(let error): // log error diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift index a279209..225cadb 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift @@ -257,6 +257,7 @@ public class FaceVerificationService { bodyParams["deviceId"] = deviceInfoEntity.deviceId bodyParams["client_id"] = enrollFaceEntity.client_id bodyParams["usage_pass"] = enrollFaceEntity.usage_pass + bodyParams["attempt"] = String(describing: enrollFaceEntity.attempt) // assign base url baseURL = (properties["DomainURL"]) ?? "" From acdb9f8f1418498ab7c383bcb6bcb4c835d057ec Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Thu, 14 Feb 2019 14:58:08 +0530 Subject: [PATCH 04/14] Touch ID asking inside SDK --- Cidaas/Classes/Core/Views/Cidaas.swift | 141 +++++++++++++++++++++---- Example/Tests/TouchIdTests.swift | 8 +- 2 files changed, 124 insertions(+), 25 deletions(-) diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index 46efa41..898cd98 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -1180,28 +1180,61 @@ public class Cidaas { // 2. Call loginWithTouchId method // 3. Maintain logs based on flags - public func loginWithTouchId(passwordlessEntity: PasswordlessEntity, extraParams: Dictionary = Dictionary(), callback: @escaping(Result) -> Void) { + public func loginWithTouchId(passwordlessEntity: PasswordlessEntity, localizedReason: String, extraParams: Dictionary = Dictionary(), callback: @escaping(Result) -> Void) { let savedProp = DBHelper.shared.getPropertyFile() if (savedProp != nil) { - if passwordlessEntity.requestId == "" { - self.getRequestId(extraParams: extraParams) { - switch $0 { - case .success(let requestIdSuccessResponse): - TouchIdVerificationController.shared.loginWithTouchId(email: passwordlessEntity.email, mobile: passwordlessEntity.mobile, sub: passwordlessEntity.sub, trackId: passwordlessEntity.trackId, requestId: requestIdSuccessResponse.data.requestId, usageType: passwordlessEntity.usageType, properties: savedProp!, callback: callback) - break - case .failure(let requestIdErrorResponse): - // return failure callback - DispatchQueue.main.async { - callback(Result.failure(error: requestIdErrorResponse)) + + // ask for touch id or face id + let touchId = TouchID() + touchId.checkIfTouchIdAvailable { (success, errorMessage, errorCode) in + if success == true { + touchId.checkTouchIDMatching(localizedReason: localizedReason, callback: { (res_success, res_errorMessage, res_errorCode) in + if res_success == true { + if passwordlessEntity.requestId == "" { + self.getRequestId(extraParams: extraParams) { + switch $0 { + case .success(let requestIdSuccessResponse): + TouchIdVerificationController.shared.loginWithTouchId(email: passwordlessEntity.email, mobile: passwordlessEntity.mobile, sub: passwordlessEntity.sub, trackId: passwordlessEntity.trackId, requestId: requestIdSuccessResponse.data.requestId, usageType: passwordlessEntity.usageType, properties: savedProp!, callback: callback) + break + case .failure(let requestIdErrorResponse): + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: requestIdErrorResponse)) + } + break + } + } + } + else { + TouchIdVerificationController.shared.loginWithTouchId(email: passwordlessEntity.email, mobile: passwordlessEntity.mobile, sub: passwordlessEntity.sub, trackId: passwordlessEntity.trackId, requestId: passwordlessEntity.requestId, usageType: passwordlessEntity.usageType, properties: savedProp!, callback: callback) + } } - break + else { + let error = WebAuthError.shared + error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + }) + } + else { + let error = WebAuthError.shared + error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) } + return } } - else { - TouchIdVerificationController.shared.loginWithTouchId(email: passwordlessEntity.email, mobile: passwordlessEntity.mobile, sub: passwordlessEntity.sub, trackId: passwordlessEntity.trackId, requestId: passwordlessEntity.requestId, usageType: passwordlessEntity.usageType, properties: savedProp!, callback: callback) - } } else { // log error @@ -1975,14 +2008,47 @@ public class Cidaas { // 2. Call enrollTouch method // 3. Maintain logs based on flags - public func enrollTouchId(sub: String, verifierPassword: String, statusId: String, callback: @escaping(Result) -> Void) { + public func enrollTouchId(sub: String, verifierPassword: String, statusId: String, localizedReason: String, callback: @escaping(Result) -> Void) { let savedProp = DBHelper.shared.getPropertyFile() if (savedProp != nil) { - let enrollTouchEntity = EnrollTouchEntity() - enrollTouchEntity.statusId = statusId - TouchIdVerificationController.shared.enrollTouchId(sub: sub, access_token: "", enrollTouchEntity: enrollTouchEntity, properties: savedProp!, callback: callback) + // ask for touch id or face id + let touchId = TouchID() + touchId.checkIfTouchIdAvailable { (success, errorMessage, errorCode) in + if success == true { + touchId.checkTouchIDMatching(localizedReason: localizedReason, callback: { (res_success, res_errorMessage, res_errorCode) in + if res_success == true { + let enrollTouchEntity = EnrollTouchEntity() + enrollTouchEntity.statusId = statusId + + TouchIdVerificationController.shared.enrollTouchId(sub: sub, access_token: "", enrollTouchEntity: enrollTouchEntity, properties: savedProp!, callback: callback) + } + else { + let error = WebAuthError.shared + error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + }) + } + else { + let error = WebAuthError.shared + error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + } } else { // log error @@ -2181,11 +2247,44 @@ public class Cidaas { // 2. Call verifyPattern method // 3. Maintain logs based on flags - public func verifyTouchId(statusId: String, callback: @escaping(Result) -> Void) { + public func verifyTouchId(statusId: String, localizedReason: String, callback: @escaping(Result) -> Void) { let savedProp = DBHelper.shared.getPropertyFile() if (savedProp != nil) { - TouchIdVerificationController.shared.verifyTouchId(statusId: statusId, properties: savedProp!, callback: callback) + + // ask for touch id or face id + let touchId = TouchID() + touchId.checkIfTouchIdAvailable { (success, errorMessage, errorCode) in + if success == true { + touchId.checkTouchIDMatching(localizedReason: localizedReason, callback: { (res_success, res_errorMessage, res_errorCode) in + if res_success == true { + TouchIdVerificationController.shared.verifyTouchId(statusId: statusId, properties: savedProp!, callback: callback) + } + else { + let error = WebAuthError.shared + error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + }) + } + else { + let error = WebAuthError.shared + error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage + error.errorCode = errorCode ?? WebAuthError.shared.errorCode + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + } } else { // log error diff --git a/Example/Tests/TouchIdTests.swift b/Example/Tests/TouchIdTests.swift index 4de3bf1..612a3fa 100644 --- a/Example/Tests/TouchIdTests.swift +++ b/Example/Tests/TouchIdTests.swift @@ -56,7 +56,7 @@ class TouchIdTests: QuickSpec { passwordlessEntity.usageType = UsageTypes.MFA.rawValue passwordlessEntity.trackId = "873472873482" - cidaas.loginWithTouchId(passwordlessEntity: passwordlessEntity) { + cidaas.loginWithTouchId(passwordlessEntity: passwordlessEntity, localizedReason: "verify touch") { switch $0 { case .failure(let error): print(error.errorMessage) @@ -78,7 +78,7 @@ class TouchIdTests: QuickSpec { passwordlessEntity.usageType = UsageTypes.MFA.rawValue passwordlessEntity.trackId = "873472873482" - cidaas.loginWithTouchId(passwordlessEntity: passwordlessEntity) { + cidaas.loginWithTouchId(passwordlessEntity: passwordlessEntity, localizedReason: "verify touch") { switch $0 { case .failure(let error): print(error.errorMessage) @@ -92,7 +92,7 @@ class TouchIdTests: QuickSpec { it("call verify TouchId from public") { - cidaas.verifyTouchId(statusId: "382b6e72-3435-4724-8339-ea7907f253e9") { + cidaas.verifyTouchId(statusId: "382b6e72-3435-4724-8339-ea7907f253e9", localizedReason: "Verify touch") { switch $0 { case .failure(let error): print(error.errorMessage) @@ -106,7 +106,7 @@ class TouchIdTests: QuickSpec { DBHelper.shared.userDefaults.removeObject(forKey: "OAuthProperty") - cidaas.verifyTouchId(statusId: "382b6e72-3435-4724-8339-ea7907f253e9") { + cidaas.verifyTouchId(statusId: "382b6e72-3435-4724-8339-ea7907f253e9", localizedReason: "Verify touch") { switch $0 { case .failure(let error): print(error.errorMessage) From 8b9236cde91cbb67c9367850879b7a3ea702b42a Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Mon, 18 Feb 2019 18:04:17 +0530 Subject: [PATCH 05/14] Added locations in all services and enabled device authentication option --- .../DeviceAuthenticationResponseEntity.swift | 27 +++++ .../Core/Helpers/Biometrics/TouchID.swift | 101 ++++++++++++++++-- .../Core/Helpers/Enums/WebAuthErrorCode.swift | 14 ++- .../Core/Helpers/General/DBHelper.swift | 19 ++++ .../Helpers/Locations/LocationDetector.swift | 35 ++++++ .../AccessToken/AccessTokenService.swift | 7 ++ .../AccountVerificationService.swift | 7 ++ .../ChangePasswordService.swift | 3 + .../Repository/Client/ClientService.swift | 3 + .../Repository/Consent/ConsentService.swift | 9 ++ .../Deduplication/DeduplicationService.swift | 7 ++ .../DocumentScan/DocumentScanService.swift | 3 + .../LinkUnlink/LinkUnlinkService.swift | 7 ++ .../Repository/Location/LocationService.swift | 9 ++ .../Repository/Login/LoginService.swift | 3 + .../Registration/RegistrationService.swift | 7 ++ .../RequestId/RequestIdService.swift | 3 + .../Resetpassword/ResetPasswordService.swift | 7 ++ .../Repository/Settings/SettingsService.swift | 9 ++ .../Repository/Tenant/TenantService.swift | 3 + .../UserActivities/UserActivityService.swift | 3 + .../Repository/Users/UsersService.swift | 5 + .../BackupcodeVerificationService.swift | 7 ++ .../Device/DeviceVerificationService.swift | 3 + .../Email/EmailVerificationService.swift | 9 ++ .../Face/FaceVerificationService.swift | 11 ++ .../IVR/IVRVerificationService.swift | 9 ++ .../Pattern/PatternVerificationService.swift | 11 ++ .../Push/PushVerificationService.swift | 11 ++ .../SMS/SMSVerificationService.swift | 9 ++ .../VerificationSettingsService.swift | 11 ++ .../TOTP/TOTPVerificationService.swift | 11 ++ .../Touch/TouchIdVerificationService.swift | 11 ++ .../Voice/VoiceVerificationService.swift | 11 ++ Cidaas/Classes/Core/Views/Cidaas.swift | 37 +++++++ Example/Cidaas/Info.plist | 2 + Example/Cidaas/ViewController.swift | 1 + 37 files changed, 432 insertions(+), 13 deletions(-) create mode 100644 Cidaas/Classes/Core/Helpers/Biometrics/DeviceAuthenticationResponseEntity.swift create mode 100644 Cidaas/Classes/Core/Helpers/Locations/LocationDetector.swift diff --git a/Cidaas/Classes/Core/Helpers/Biometrics/DeviceAuthenticationResponseEntity.swift b/Cidaas/Classes/Core/Helpers/Biometrics/DeviceAuthenticationResponseEntity.swift new file mode 100644 index 0000000..053ae8f --- /dev/null +++ b/Cidaas/Classes/Core/Helpers/Biometrics/DeviceAuthenticationResponseEntity.swift @@ -0,0 +1,27 @@ +// +// DeviceAuthenticationResponseEntity.swift +// Cidaas +// +// Created by ganesh on 18/02/19. +// + +import Foundation + +public class DeviceAuthenticationResponseEntity: Codable { + // properties + public var success: Bool = false + public var status: Int32 = 400 + public var message: String = "" + + // Constructors + public init() { + + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.success = try container.decodeIfPresent(Bool.self, forKey: .success) ?? false + self.status = try container.decodeIfPresent(Int32.self, forKey: .status) ?? 400 + self.message = try container.decodeIfPresent(String.self, forKey: .message) ?? "" + } +} diff --git a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift index 65e460e..278c900 100644 --- a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift +++ b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift @@ -11,7 +11,7 @@ import LocalAuthentication public class TouchID { public static let sharedInstance = TouchID() - let authenticatedContext = LAContext() + var authenticatedContext = LAContext() var error: NSError? public func checkIfTouchIdAvailable(callback: @escaping (Bool, String?, Int32?)->()) { @@ -27,6 +27,91 @@ public class TouchID { callback(false, "TouchId not available", WebAuthErrorCode.TOUCHID_NOT_AVAILABLE.rawValue) } break + case LAError.invalidContext.rawValue: + self.authenticatedContext = LAContext() + self.checkIfTouchIdAvailable(callback: callback) + DispatchQueue.main.async { + callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) + } + break + case LAError.touchIDNotEnrolled.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not enrolled", WebAuthErrorCode.TOUCHID_NOT_ENROLLED.rawValue) + } + break + case LAError.passcodeNotSet.rawValue: + DispatchQueue.main.async { + callback(false, "Passcode not configured", WebAuthErrorCode.TOUCH_ID_PASSCODE_NOT_CONFIGURED.rawValue) + } + break + case LAError.authenticationFailed.rawValue: + DispatchQueue.main.async { + callback(false, "Invalid authentication", WebAuthErrorCode.TOUCH_ID_INVALID_AUTHENTICATION.rawValue) + } + break + case LAError.appCancel.rawValue: + DispatchQueue.main.async { + callback(false, "App cancelled", WebAuthErrorCode.TOUCH_ID_APP_CANCELLED.rawValue) + } + break + case LAError.systemCancel.rawValue: + DispatchQueue.main.async { + callback(false, "System cancelled", WebAuthErrorCode.TOUCH_ID_SYSTEM_CANCELLED.rawValue) + } + break + case LAError.userCancel.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + case LAError.touchIDLockout.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId locked", WebAuthErrorCode.TOUCHID_LOCKED.rawValue) + } + break + case LAError.userFallback.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + case LAError.notInteractive.rawValue: + DispatchQueue.main.async { + callback(false, "Not interactive", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + default: + DispatchQueue.main.async { + callback(false, "Error occured", WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + } + break + } + } + } + + public func checkIfPasscodeAvailable(invalidateAuthenticationContext: Bool, callback: @escaping (Bool, String?, Int32?)->()) { + if invalidateAuthenticationContext == true { + self.authenticatedContext.invalidate() + } + + if authenticatedContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) { + DispatchQueue.main.async { + callback(true, nil, nil) + } + } + else { + switch error!.code { + case LAError.touchIDNotAvailable.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not available", WebAuthErrorCode.TOUCHID_NOT_AVAILABLE.rawValue) + } + break + case LAError.invalidContext.rawValue: + self.authenticatedContext = LAContext() + self.checkIfPasscodeAvailable(invalidateAuthenticationContext: false, callback: callback) + DispatchQueue.main.async { + callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) + } + break case LAError.touchIDNotEnrolled.rawValue: DispatchQueue.main.async { callback(false, "TouchId not enrolled", WebAuthErrorCode.TOUCHID_NOT_ENROLLED.rawValue) @@ -34,27 +119,27 @@ public class TouchID { break case LAError.passcodeNotSet.rawValue: DispatchQueue.main.async { - callback(false, "Passcode not configured", WebAuthErrorCode.PASSCODE_NOT_CONFIGURED.rawValue) + callback(false, "Passcode not configured", WebAuthErrorCode.TOUCH_ID_PASSCODE_NOT_CONFIGURED.rawValue) } break case LAError.authenticationFailed.rawValue: DispatchQueue.main.async { - callback(false, "Invalid authentication", WebAuthErrorCode.INVALID_AUTHENTICATION.rawValue) + callback(false, "Invalid authentication", WebAuthErrorCode.TOUCH_ID_INVALID_AUTHENTICATION.rawValue) } break case LAError.appCancel.rawValue: DispatchQueue.main.async { - callback(false, "App cancelled", WebAuthErrorCode.APP_CANCELLED.rawValue) + callback(false, "App cancelled", WebAuthErrorCode.TOUCH_ID_APP_CANCELLED.rawValue) } break case LAError.systemCancel.rawValue: DispatchQueue.main.async { - callback(false, "System cancelled", WebAuthErrorCode.SYSTEM_CANCELLED.rawValue) + callback(false, "System cancelled", WebAuthErrorCode.TOUCH_ID_SYSTEM_CANCELLED.rawValue) } break case LAError.userCancel.rawValue: DispatchQueue.main.async { - callback(false, "User cancelled", WebAuthErrorCode.USER_CANCELLED.rawValue) + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) } break case LAError.touchIDLockout.rawValue: @@ -64,7 +149,7 @@ public class TouchID { break case LAError.userFallback.rawValue: DispatchQueue.main.async { - callback(false, "User cancelled", WebAuthErrorCode.USER_CANCELLED.rawValue) + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) } break default: @@ -77,7 +162,7 @@ public class TouchID { } public func checkTouchIDMatching(localizedReason: String, callback: @escaping (Bool, String?, Int32?)->()) { - authenticatedContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: localizedReason, reply: { (success, error) -> Void in + authenticatedContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: localizedReason, reply: { (success, error) -> Void in if( success ) { DispatchQueue.main.async { callback(true, nil, nil) diff --git a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift index 83ad548..f719bf9 100644 --- a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift +++ b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift @@ -213,14 +213,18 @@ public enum WebAuthErrorCode : Int32 { case UPDATE_FCM_SERVICE_FAILURE = 10176 case PENDING_NOTIFICATION_LIST_SERVICE_FAILURE = 10177 + + case TOUCHID_NOT_AVAILABLE = 10178 case TOUCHID_NOT_ENROLLED = 10179 - case PASSCODE_NOT_CONFIGURED = 10180 - case INVALID_AUTHENTICATION = 10181 - case APP_CANCELLED = 10182 - case SYSTEM_CANCELLED = 10183 - case USER_CANCELLED = 10184 + case TOUCH_ID_PASSCODE_NOT_CONFIGURED = 10180 + case TOUCH_ID_INVALID_AUTHENTICATION = 10181 + case TOUCH_ID_APP_CANCELLED = 10182 + case TOUCH_ID_SYSTEM_CANCELLED = 10183 + case TOUCH_ID_USER_CANCELLED = 10184 case TOUCHID_LOCKED = 10185 case TOUCHID_DEFAULT_ERROR = 10186 + case TOUCHID_INVALID_CONTEXT = 10187 + case TOUCHID_NOT_INTERACTIVE = 10188 } diff --git a/Cidaas/Classes/Core/Helpers/General/DBHelper.swift b/Cidaas/Classes/Core/Helpers/General/DBHelper.swift index 82c785f..cea7566 100644 --- a/Cidaas/Classes/Core/Helpers/General/DBHelper.swift +++ b/Cidaas/Classes/Core/Helpers/General/DBHelper.swift @@ -198,4 +198,23 @@ public class DBHelper : NSObject { } return value as? String ?? "" } + + // set location + public func setLocation(lat: String, lon: String, key: String = "OAuthLocation") { + userDefaults.set(lat + "-" + lon, forKey: key) + userDefaults.synchronize() + } + + // get location + public func getLocation(key: String = "OAuthLocation") -> (String, String) { + guard let value = userDefaults.object(forKey: key) else { + return ("", "") + } + // split by hyphen + var splittedLocation: [Substring] = (value as? String ?? "").split(separator: "-") + if splittedLocation.count > 1 { + return (String(splittedLocation[0]), String(splittedLocation[1])) + } + return ("", "") + } } diff --git a/Cidaas/Classes/Core/Helpers/Locations/LocationDetector.swift b/Cidaas/Classes/Core/Helpers/Locations/LocationDetector.swift new file mode 100644 index 0000000..3998f67 --- /dev/null +++ b/Cidaas/Classes/Core/Helpers/Locations/LocationDetector.swift @@ -0,0 +1,35 @@ +// +// File.swift +// Cidaas +// +// Created by ganesh on 18/02/19. +// + +import Foundation +import CoreLocation + +public class LocationDetector: NSObject, CLLocationManagerDelegate { + + var locationManager : CLLocationManager = CLLocationManager() + var latitude: String = "" + var longitude: String = "" + + public func startTracking() { + locationManager.desiredAccuracy = kCLLocationAccuracyBest + locationManager.delegate = self + locationManager.requestWhenInUseAuthorization() + locationManager.startUpdatingLocation() + } + + + public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + let lastLocation: CLLocation = locations[locations.count - 1] + latitude = String(format: "%.6f", lastLocation.coordinate.latitude) + longitude = String(format: "%.6f", lastLocation.coordinate.longitude) + updateLocation() + } + + public func updateLocation() { + DBHelper.shared.setLocation(lat: latitude, lon: longitude) + } +} diff --git a/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift b/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift index dcf6195..c6a33f5 100644 --- a/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift +++ b/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift @@ -13,6 +13,7 @@ public class AccessTokenService { // shared instance public static var shared : AccessTokenService = AccessTokenService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -35,6 +36,8 @@ public class AccessTokenService { "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, "deviceVersion" : deviceInfoEntity.deviceVersion, + "lat": location.0, + "lon": location.1, "Content-Type" : "application/x-www-form-urlencoded" ] @@ -112,6 +115,8 @@ public class AccessTokenService { "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, "deviceVersion" : deviceInfoEntity.deviceVersion, + "lat": location.0, + "lon": location.1, "Content-Type" : "application/x-www-form-urlencoded" ] @@ -179,6 +184,8 @@ public class AccessTokenService { "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, "deviceVersion" : deviceInfoEntity.deviceVersion, + "lat": location.0, + "lon": location.1, "Content-Type" : "application/x-www-form-urlencoded" ] diff --git a/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift index 374dfa8..317df65 100644 --- a/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift @@ -13,6 +13,7 @@ public class AccountVerificationService { // shared instance public static var shared : AccountVerificationService = AccountVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -36,6 +37,8 @@ public class AccountVerificationService { "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, + "lat": location.0, + "lon": location.1, "deviceVersion" : deviceInfoEntity.deviceVersion ] @@ -131,6 +134,8 @@ public class AccountVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -229,6 +234,8 @@ public class AccountVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift b/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift index 2df0963..3b0c48d 100644 --- a/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift @@ -13,6 +13,7 @@ public class ChangePasswordService { // shared instance public static var shared : ChangePasswordService = ChangePasswordService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -33,6 +34,8 @@ public class ChangePasswordService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, diff --git a/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift b/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift index d40ff78..19ad92b 100644 --- a/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift @@ -13,6 +13,7 @@ public class ClientService { // shared instance public static var shared : ClientService = ClientService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class ClientService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift b/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift index 4151ece..6dfa257 100644 --- a/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift @@ -13,6 +13,7 @@ public class ConsentService { // shared instance public static var shared : ConsentService = ConsentService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class ConsentService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -123,6 +126,8 @@ public class ConsentService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -213,6 +218,8 @@ public class ConsentService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -316,6 +323,8 @@ public class ConsentService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift b/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift index 9cf5a50..17d56ba 100644 --- a/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift @@ -13,6 +13,7 @@ public class DeduplicationService { // shared instance public static var shared : DeduplicationService = DeduplicationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -33,6 +34,8 @@ public class DeduplicationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -118,6 +121,8 @@ public class DeduplicationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -203,6 +208,8 @@ public class DeduplicationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift b/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift index 4085ffe..6295b2d 100644 --- a/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift +++ b/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift @@ -12,6 +12,7 @@ public class DocumentScanService { // shared instance public static var shared : DocumentScanService = DocumentScanService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class DocumentScanService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, diff --git a/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift b/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift index 5d4ac35..56fdef0 100644 --- a/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift +++ b/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift @@ -13,6 +13,7 @@ public class LinkUnlinkService { // shared instance public static var shared : LinkUnlinkService = LinkUnlinkService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -33,6 +34,8 @@ public class LinkUnlinkService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": accessToken, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, @@ -124,6 +127,8 @@ public class LinkUnlinkService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": accessToken, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, @@ -210,6 +215,8 @@ public class LinkUnlinkService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": accessToken, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, diff --git a/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift b/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift index 05b892d..e286851 100644 --- a/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift @@ -12,6 +12,7 @@ public class LocationService { // shared instance public static var shared : LocationService = LocationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class LocationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -118,6 +121,8 @@ public class LocationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -218,6 +223,8 @@ public class LocationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -303,6 +310,8 @@ public class LocationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift b/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift index 649e4f0..74c2677 100644 --- a/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift @@ -13,6 +13,7 @@ public class LoginService { // shared instance public static var shared : LoginService = LoginService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class LoginService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift b/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift index d4e49ab..46b9619 100644 --- a/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift @@ -13,6 +13,7 @@ public class RegistrationService { // shared instance public static var shared : RegistrationService = RegistrationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class RegistrationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -118,6 +121,8 @@ public class RegistrationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "requestId": requestId, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, @@ -218,6 +223,8 @@ public class RegistrationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, diff --git a/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift b/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift index 9493cbf..1c1ef31 100644 --- a/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift +++ b/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift @@ -13,6 +13,7 @@ public class RequestIdService { // shared instance public static var shared : RequestIdService = RequestIdService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class RequestIdService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift b/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift index 026b255..7d2f197 100644 --- a/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift @@ -13,6 +13,7 @@ public class ResetPasswordService { // shared instance public static var shared : ResetPasswordService = ResetPasswordService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -33,6 +34,8 @@ public class ResetPasswordService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -132,6 +135,8 @@ public class ResetPasswordService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -230,6 +235,8 @@ public class ResetPasswordService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift b/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift index c0f37ae..56158d1 100644 --- a/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift @@ -11,6 +11,7 @@ import Alamofire public class SettingsService { // shared instance public static var shared : SettingsService = SettingsService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -31,6 +32,8 @@ public class SettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -116,6 +119,8 @@ public class SettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -207,6 +212,8 @@ public class SettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -298,6 +305,8 @@ public class SettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift b/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift index 240a423..683a898 100644 --- a/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift @@ -13,6 +13,7 @@ public class TenantService { // shared instance public static var shared : TenantService = TenantService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class TenantService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift index e15e2e5..fb018c6 100644 --- a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift +++ b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift @@ -13,6 +13,7 @@ public class UserActivityService { // shared instance public static var shared : UserActivityService = UserActivityService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -33,6 +34,8 @@ public class UserActivityService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": accessToken, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, diff --git a/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift b/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift index 5516c6b..0cb9df6 100644 --- a/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift @@ -13,6 +13,7 @@ public class UsersService { // shared instance public static var shared : UsersService = UsersService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -33,6 +34,8 @@ public class UsersService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": accessToken, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, @@ -115,6 +118,8 @@ public class UsersService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token" : accessToken ] diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift index 099b60f..ae00b74 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift @@ -13,6 +13,7 @@ public class BackupcodeVerificationService { // shared instance public static var shared : BackupcodeVerificationService = BackupcodeVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -31,6 +32,8 @@ public class BackupcodeVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token ] @@ -132,6 +135,8 @@ public class BackupcodeVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -231,6 +236,8 @@ public class BackupcodeVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift index 8b9d0da..262408f 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift @@ -13,6 +13,7 @@ public class DeviceVerificationService { // shared instance public static var shared : DeviceVerificationService = DeviceVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -36,6 +37,8 @@ public class DeviceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] validateDeviceEntity.deviceInfo = deviceInfoEntity diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift index fe1b06c..99023c2 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift @@ -13,6 +13,7 @@ public class EmailVerificationService { // shared instance public static var shared : EmailVerificationService = EmailVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class EmailVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token ] @@ -137,6 +140,8 @@ public class EmailVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -236,6 +241,8 @@ public class EmailVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -334,6 +341,8 @@ public class EmailVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift index 225cadb..c851146 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift @@ -13,6 +13,7 @@ public class FaceVerificationService { // shared instance public static var shared : FaceVerificationService = FaceVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -35,6 +36,8 @@ public class FaceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -137,6 +140,8 @@ public class FaceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -239,6 +244,8 @@ public class FaceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -360,6 +367,8 @@ public class FaceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -459,6 +468,8 @@ public class FaceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift index 2195691..c4a65b3 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift @@ -13,6 +13,7 @@ public class IVRVerificationService { // shared instance public static var shared : IVRVerificationService = IVRVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class IVRVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token ] @@ -138,6 +141,8 @@ public class IVRVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -237,6 +242,8 @@ public class IVRVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -335,6 +342,8 @@ public class IVRVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift index c1e1e25..0f439a1 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift @@ -13,6 +13,7 @@ public class PatternVerificationService { // shared instance public static var shared : PatternVerificationService = PatternVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -35,6 +36,8 @@ public class PatternVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2", "access_token" : accessToken ] @@ -137,6 +140,8 @@ public class PatternVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] @@ -239,6 +244,8 @@ public class PatternVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2", "access_token" : accessToken ] @@ -342,6 +349,8 @@ public class PatternVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] @@ -441,6 +450,8 @@ public class PatternVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift index aaf9418..759ce7c 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift @@ -13,6 +13,7 @@ public class PushVerificationService { // shared instance public static var shared : PushVerificationService = PushVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -35,6 +36,8 @@ public class PushVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -137,6 +140,8 @@ public class PushVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -239,6 +244,8 @@ public class PushVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -342,6 +349,8 @@ public class PushVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -441,6 +450,8 @@ public class PushVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift index f94bf4a..3d90f0e 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift @@ -13,6 +13,7 @@ public class SMSVerificationService { // shared instance public static var shared : SMSVerificationService = SMSVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class SMSVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "access_token": access_token ] @@ -137,6 +140,8 @@ public class SMSVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -236,6 +241,8 @@ public class SMSVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params @@ -334,6 +341,8 @@ public class SMSVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1 ] // construct body params diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift index bf3c697..323e1bf 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift @@ -13,6 +13,7 @@ public class VerificationSettingsService { // shared instance public static var shared : VerificationSettingsService = VerificationSettingsService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -32,6 +33,8 @@ public class VerificationSettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -130,6 +133,8 @@ public class VerificationSettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -228,6 +233,8 @@ public class VerificationSettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId" : deviceInfoEntity.deviceId, "deviceMake" : deviceInfoEntity.deviceMake, "deviceModel" : deviceInfoEntity.deviceModel, @@ -326,6 +333,8 @@ public class VerificationSettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId": deviceInfoEntity.deviceId, "deviceMake": deviceInfoEntity.deviceMake, "deviceModel": deviceInfoEntity.deviceModel, @@ -417,6 +426,8 @@ public class VerificationSettingsService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "deviceId": deviceInfoEntity.deviceId, "deviceMake": deviceInfoEntity.deviceMake, "deviceModel": deviceInfoEntity.deviceModel, diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift index e5760f9..e6008fc 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift @@ -13,6 +13,7 @@ public class TOTPVerificationService { // shared instance public static var shared : TOTPVerificationService = TOTPVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -35,6 +36,8 @@ public class TOTPVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -137,6 +140,8 @@ public class TOTPVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -239,6 +244,8 @@ public class TOTPVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -342,6 +349,8 @@ public class TOTPVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -441,6 +450,8 @@ public class TOTPVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift index 52272d4..d42bcf9 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift @@ -13,6 +13,7 @@ public class TouchIdVerificationService { // shared instance public static var shared : TouchIdVerificationService = TouchIdVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -35,6 +36,8 @@ public class TouchIdVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -137,6 +140,8 @@ public class TouchIdVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -239,6 +244,8 @@ public class TouchIdVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -343,6 +350,8 @@ public class TouchIdVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -442,6 +451,8 @@ public class TouchIdVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift index 597d9f0..fd7e888 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift @@ -14,6 +14,7 @@ public class VoiceVerificationService { // shared instance public static var shared : VoiceVerificationService = VoiceVerificationService() + let location = DBHelper.shared.getLocation() // constructor public init() { @@ -36,6 +37,8 @@ public class VoiceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -138,6 +141,8 @@ public class VoiceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -240,6 +245,8 @@ public class VoiceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2", "access_token" : accessToken ] @@ -358,6 +365,8 @@ public class VoiceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version" : "2" ] @@ -457,6 +466,8 @@ public class VoiceVerificationService { // construct headers headers = [ "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, "verification_api_version": "2" ] diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index 898cd98..2454984 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -29,6 +29,7 @@ public class Cidaas { var trackingManager: TrackingManager! var browserCallback: ((Result) -> ())! var propertyFileRead: Bool = false + var locationDetector : LocationDetector // static variables public static var intermediate_verifiation_id: String = "" @@ -89,6 +90,9 @@ public class Cidaas { deviceInfo.deviceVersion = UIDevice.current.systemVersion DBHelper.shared.setDeviceInfo(deviceInfo: deviceInfo) + locationDetector = LocationDetector() + locationDetector.startTracking() + // set storage in local self.storage = storage @@ -405,6 +409,39 @@ public class Cidaas { } } +// -------------------------------------------------------------------------------------------------- // + + // call biometrics + // 1. call biometrics + // 2. Maintain logs based on flags + public func askDeviceAuthentication(localizedReason: String, invalidateAuthenticationContext: Bool = false, callback: @escaping (DeviceAuthenticationResponseEntity) -> Void) { + let touch = TouchID() + let response = DeviceAuthenticationResponseEntity() + touch.checkIfPasscodeAvailable(invalidateAuthenticationContext: invalidateAuthenticationContext, callback: { (success_pass, message_pass, code_pass) in + if success_pass == true { + touch.checkTouchIDMatching(localizedReason: localizedReason, callback: { (success_inner, message_inner, code_inner) in + if success_inner == true { + response.success = true + response.status = 200 + response.message = "Authentication success" + } + else { + // failure callback + response.success = success_inner + response.status = code_inner ?? 400 + response.message = message_inner ?? "Authentication Failed" + } + }) + } + else { + // failure callback + response.success = success_pass + response.status = code_pass ?? 400 + response.message = message_pass ?? "Authentication Failed" + } + }) + } + // -------------------------------------------------------------------------------------------------- // // get tenant info from plist diff --git a/Example/Cidaas/Info.plist b/Example/Cidaas/Info.plist index 82c8110..bfccae2 100644 --- a/Example/Cidaas/Info.plist +++ b/Example/Cidaas/Info.plist @@ -2,6 +2,8 @@ + NSLocationUsageDescription + Location NSFaceIDUsageDescription Face Id CFBundleDevelopmentRegion diff --git a/Example/Cidaas/ViewController.swift b/Example/Cidaas/ViewController.swift index 8b2bbfe..a5150ca 100644 --- a/Example/Cidaas/ViewController.swift +++ b/Example/Cidaas/ViewController.swift @@ -30,6 +30,7 @@ class ViewController: UIViewController, WKNavigationDelegate, CidaasLoaderDelega CidaasFacebook.shared.delegate = self CidaasGoogle.shared.delegate = self + // cidaasView.loginWithEmbeddedBrowser(delegate: self) { // switch $0 { // case .success(let result): From e0b3367850b0e03baec478f2268a6ea18df5706f Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 19 Feb 2019 11:53:10 +0530 Subject: [PATCH 06/14] Touch Id callback issue fixes --- .../Core/Helpers/Biometrics/TouchID.swift | 65 ++++++++++++++++++- Cidaas/Classes/Core/Views/Cidaas.swift | 8 +++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift index 278c900..ad61121 100644 --- a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift +++ b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift @@ -168,8 +168,69 @@ public class TouchID { callback(true, nil, nil) } }else { - DispatchQueue.main.async { - callback(false, error?.localizedDescription, WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + switch error!._code { + case LAError.touchIDNotAvailable.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not available", WebAuthErrorCode.TOUCHID_NOT_AVAILABLE.rawValue) + } + break + case LAError.invalidContext.rawValue: + self.authenticatedContext = LAContext() + self.checkIfTouchIdAvailable(callback: callback) + DispatchQueue.main.async { + callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) + } + break + case LAError.touchIDNotEnrolled.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not enrolled", WebAuthErrorCode.TOUCHID_NOT_ENROLLED.rawValue) + } + break + case LAError.passcodeNotSet.rawValue: + DispatchQueue.main.async { + callback(false, "Passcode not configured", WebAuthErrorCode.TOUCH_ID_PASSCODE_NOT_CONFIGURED.rawValue) + } + break + case LAError.authenticationFailed.rawValue: + DispatchQueue.main.async { + callback(false, "Invalid authentication", WebAuthErrorCode.TOUCH_ID_INVALID_AUTHENTICATION.rawValue) + } + break + case LAError.appCancel.rawValue: + DispatchQueue.main.async { + callback(false, "App cancelled", WebAuthErrorCode.TOUCH_ID_APP_CANCELLED.rawValue) + } + break + case LAError.systemCancel.rawValue: + DispatchQueue.main.async { + callback(false, "System cancelled", WebAuthErrorCode.TOUCH_ID_SYSTEM_CANCELLED.rawValue) + } + break + case LAError.userCancel.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + case LAError.touchIDLockout.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId locked", WebAuthErrorCode.TOUCHID_LOCKED.rawValue) + } + break + case LAError.userFallback.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + case LAError.notInteractive.rawValue: + DispatchQueue.main.async { + callback(false, "Not interactive", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + default: + DispatchQueue.main.async { + callback(false, "Error occured", WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + } + break } } }) diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index 2454984..9d214a9 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -431,6 +431,10 @@ public class Cidaas { response.status = code_inner ?? 400 response.message = message_inner ?? "Authentication Failed" } + DispatchQueue.main.async { + callback(response) + return + } }) } else { @@ -439,6 +443,10 @@ public class Cidaas { response.status = code_pass ?? 400 response.message = message_pass ?? "Authentication Failed" } + DispatchQueue.main.async { + callback(response) + return + } }) } From 4f38183a7c4d4e5c2c919f6d3ae447128aa775a5 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 19 Feb 2019 14:27:56 +0530 Subject: [PATCH 07/14] Network Time out error fixes --- .../Core/Helpers/Enums/HttpStatusCode.swift | 1 + .../Core/Helpers/Enums/WebAuthErrorCode.swift | 1 + .../Helpers/Extensions/WebAuthError.swift | 11 ++ .../Core/Helpers/Locale/StringsHelper.swift | 1 + .../AccessToken/AccessTokenService.swift | 21 ++- .../AccountVerificationService.swift | 21 ++- .../ChangePasswordService.swift | 7 +- .../Repository/Client/ClientService.swift | 7 +- .../Repository/Consent/ConsentService.swift | 28 +++- .../Deduplication/DeduplicationService.swift | 21 ++- .../DocumentScan/DocumentScanService.swift | 5 + .../LinkUnlink/LinkUnlinkService.swift | 21 ++- .../Repository/Location/LocationService.swift | 128 ++++++++++-------- .../Repository/Login/LoginService.swift | 7 +- .../Registration/RegistrationService.swift | 21 ++- .../RequestId/RequestIdService.swift | 7 +- .../Resetpassword/ResetPasswordService.swift | 21 ++- .../Repository/Settings/SettingsService.swift | 28 +++- .../Repository/Tenant/TenantService.swift | 7 +- .../UserActivities/UserActivityService.swift | 7 +- .../Repository/Users/UsersService.swift | 12 +- .../BackupcodeVerificationService.swift | 21 ++- .../Device/DeviceVerificationService.swift | 7 +- .../Email/EmailVerificationService.swift | 28 +++- .../Face/FaceVerificationService.swift | 31 ++++- .../IVR/IVRVerificationService.swift | 28 +++- .../Pattern/PatternVerificationService.swift | 35 ++++- .../Push/PushVerificationService.swift | 35 ++++- .../SMS/SMSVerificationService.swift | 28 +++- .../VerificationSettingsService.swift | 30 +++- .../TOTP/TOTPVerificationService.swift | 35 ++++- .../Touch/TouchIdVerificationService.swift | 35 ++++- .../Voice/VoiceVerificationService.swift | 31 ++++- Example/Cidaas/ViewController.swift | 51 +------ 34 files changed, 595 insertions(+), 183 deletions(-) diff --git a/Cidaas/Classes/Core/Helpers/Enums/HttpStatusCode.swift b/Cidaas/Classes/Core/Helpers/Enums/HttpStatusCode.swift index 7d1ac22..e481009 100644 --- a/Cidaas/Classes/Core/Helpers/Enums/HttpStatusCode.swift +++ b/Cidaas/Classes/Core/Helpers/Enums/HttpStatusCode.swift @@ -26,4 +26,5 @@ public enum HttpStatusCode : Int { case DEFAULT = 501 case BAD_GATEWAY = 502 case SERVICE_UNAVAILABLE = 503 + case GATEWAY_TIMEOUT = 504 } diff --git a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift index f719bf9..32d92e2 100644 --- a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift +++ b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift @@ -227,4 +227,5 @@ public enum WebAuthErrorCode : Int32 { case TOUCHID_INVALID_CONTEXT = 10187 case TOUCHID_NOT_INTERACTIVE = 10188 + case NETWORK_TIMEOUT = 10189 } diff --git a/Cidaas/Classes/Core/Helpers/Extensions/WebAuthError.swift b/Cidaas/Classes/Core/Helpers/Extensions/WebAuthError.swift index bd827e1..237bc69 100644 --- a/Cidaas/Classes/Core/Helpers/Extensions/WebAuthError.swift +++ b/Cidaas/Classes/Core/Helpers/Extensions/WebAuthError.swift @@ -43,6 +43,7 @@ public class WebAuthError : Error, OauthExceptionDelegate { WebAuthError.shared.errorMessage = StringsHelper.shared.NOTIFICATION_TIMEOUT WebAuthError.shared.statusCode = HttpStatusCode.EXPECTATION_FAILED.rawValue WebAuthError.shared.error = ErrorResponseEntity() + WebAuthError.shared.error.error.code = WebAuthErrorCode.NOTIFICATION_TIMEOUT.rawValue return WebAuthError.shared } @@ -73,6 +74,16 @@ public class WebAuthError : Error, OauthExceptionDelegate { return WebAuthError.shared } + // login url missing exception + public func netWorkTimeoutException() -> WebAuthError { + WebAuthError.shared.errorCode = WebAuthErrorCode.NETWORK_TIMEOUT.rawValue + WebAuthError.shared.errorMessage = StringsHelper.shared.NETWORK_TIMEOUT + WebAuthError.shared.statusCode = HttpStatusCode.GATEWAY_TIMEOUT.rawValue + WebAuthError.shared.error = ErrorResponseEntity() + WebAuthError.shared.error.error.code = WebAuthErrorCode.NETWORK_TIMEOUT.rawValue + return WebAuthError.shared + } + // login url missing exception public func loginURLMissingException() -> WebAuthError { WebAuthError.shared.errorCode = WebAuthErrorCode.EMPTY_LOGIN_URL.rawValue diff --git a/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift b/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift index e430618..101f68d 100644 --- a/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift +++ b/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift @@ -223,4 +223,5 @@ public class StringsHelper { public var DENY_REQUEST_SERVICE_FAILURE: String = "Deny request service failure" public var UPDATE_FCM_SERVICE_FAILURE: String = "Update FCM token service failure" public var PENDING_NOTIFICATION_LIST_SERVICE_FAILURE: String = "Pending notification service failure" + public var NETWORK_TIMEOUT: String = "Network Timeout" } diff --git a/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift b/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift index c6a33f5..49e9368 100644 --- a/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift +++ b/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift @@ -65,7 +65,12 @@ public class AccessTokenService { // call service Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ACCESSTOKEN_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.ACCESS_TOKEN_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) return @@ -134,7 +139,12 @@ public class AccessTokenService { // call service Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.REFRESH_TOKEN_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.REFRESH_TOKEN_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) return @@ -205,7 +215,12 @@ public class AccessTokenService { // call service Alamofire.request(urlString, method: .get, headers: headers).validate(statusCode: 200..<308).responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.SOCIAL_TOKEN_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.SOCIAL_TOKEN_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) return diff --git a/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift index 317df65..5af224e 100644 --- a/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift @@ -68,7 +68,12 @@ public class AccountVerificationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -168,7 +173,12 @@ public class AccountVerificationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -255,7 +265,12 @@ public class AccountVerificationService { Alamofire.request(urlString, method: .get, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift b/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift index 3b0c48d..f250470 100644 --- a/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift @@ -71,7 +71,12 @@ public class ChangePasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift b/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift index 19ad92b..4fcd1bc 100644 --- a/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift @@ -82,7 +82,12 @@ public class ClientService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.CLIENT_INFO_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.CLIENT_INFO_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift b/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift index 6dfa257..1e1fefb 100644 --- a/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift @@ -86,7 +86,12 @@ public class ConsentService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.CONSENT_URL_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.CONSENT_URL_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -179,7 +184,12 @@ public class ConsentService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.CONSENT_DETAILS_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.CONSENT_DETAILS_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -284,7 +294,12 @@ public class ConsentService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ACCEPT_CONSENT_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.ACCEPT_CONSENT_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -384,7 +399,12 @@ public class ConsentService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.CONSENT_CONTINUE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.CONSENT_CONTINUE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift b/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift index 17d56ba..902954d 100644 --- a/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift @@ -55,7 +55,12 @@ public class DeduplicationService { Alamofire.request(urlString, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -142,7 +147,12 @@ public class DeduplicationService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -244,7 +254,12 @@ public class DeduplicationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift b/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift index 6295b2d..69966c6 100644 --- a/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift +++ b/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift @@ -116,6 +116,11 @@ public class DocumentScanService { } break case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.DOCUMENT_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) break diff --git a/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift b/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift index 56fdef0..6cfb531 100644 --- a/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift +++ b/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift @@ -61,7 +61,12 @@ public class LinkUnlinkService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -149,7 +154,12 @@ public class LinkUnlinkService { Alamofire.request(urlString, method: .get, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -237,7 +247,12 @@ public class LinkUnlinkService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift b/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift index e286851..95fb725 100644 --- a/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift @@ -55,7 +55,12 @@ public class LocationService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -155,57 +160,62 @@ public class LocationService { urlString = baseURL + URLHelper.shared.getLocationEmissionURL() Alamofire.request(urlString, method: .post, parameters: bodyParams, encoding: JSONEncoding.default, - headers: headers).validate().responseString { response in - switch response.result { - case .failure: - if (response.data != nil) { - let jsonString = String(decoding: response.data!, as: UTF8.self) - let decoder = JSONDecoder() - do { - let data = jsonString.data(using: .utf8)! - // decode the json data to object - let errorResponseEntity = try decoder.decode(ErrorResponseEntity.self, from: data) - - // return failure - callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: errorResponseEntity.error.error, statusCode: Int(errorResponseEntity.status), error: errorResponseEntity))) - } - catch(let error) { - // return failure - callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) - } - } - else { - // return failure - callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOCATION_EMISSION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) - } - return - case .success: - if response.response?.statusCode == 200 { - if let jsonString = response.result.value { - let decoder = JSONDecoder() - do { - let data = jsonString.data(using: .utf8)! - let locationSearch = try decoder.decode(EmissionResponse.self, from: data) - // return success - callback(Result.success(result: locationSearch)) - } - catch { - // return failure - callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ERROR_JSON_PARSING.rawValue, errorMessage: StringsHelper.shared.ERROR_JSON_PARSING, statusCode: HttpStatusCode.DEFAULT.rawValue))) - return - } - } - else { - // return failure - callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOCATION_EMISSION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) - } - } - else { - // return failure - callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOCATION_EMISSION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) - break - } - } + headers: headers).validate().responseString { response in + switch response.result { + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } + if (response.data != nil) { + let jsonString = String(decoding: response.data!, as: UTF8.self) + let decoder = JSONDecoder() + do { + let data = jsonString.data(using: .utf8)! + // decode the json data to object + let errorResponseEntity = try decoder.decode(ErrorResponseEntity.self, from: data) + + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: errorResponseEntity.error.error, statusCode: Int(errorResponseEntity.status), error: errorResponseEntity))) + } + catch(let error) { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) + } + } + else { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOCATION_EMISSION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) + } + return + case .success: + if response.response?.statusCode == 200 { + if let jsonString = response.result.value { + let decoder = JSONDecoder() + do { + let data = jsonString.data(using: .utf8)! + let locationSearch = try decoder.decode(EmissionResponse.self, from: data) + // return success + callback(Result.success(result: locationSearch)) + } + catch { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ERROR_JSON_PARSING.rawValue, errorMessage: StringsHelper.shared.ERROR_JSON_PARSING, statusCode: HttpStatusCode.DEFAULT.rawValue))) + return + } + } + else { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOCATION_EMISSION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) + } + } + else { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOCATION_EMISSION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOCATION_EMISSION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) + break + } + } } } @@ -244,7 +254,12 @@ public class LocationService { Alamofire.request(urlString, method: .get, parameters: nil, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -346,7 +361,12 @@ public class LocationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, encoding: JSONEncoding.default, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift b/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift index 74c2677..2225c7d 100644 --- a/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift @@ -97,7 +97,12 @@ public class LoginService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.LOGIN_WITH_CREDENTIAL_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.LOGIN_WITH_CREDENTIAL_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift b/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift index 46b9619..9d2bda5 100644 --- a/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift @@ -82,7 +82,12 @@ public class RegistrationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.REGISTRATION_FIELDS_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.REGISTRATION_FIELDS_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -184,7 +189,12 @@ public class RegistrationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.REGISTRATION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.REGISTRATION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -286,7 +296,12 @@ public class RegistrationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.UPDATE_USER_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.UPDATE_USER_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift b/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift index 1c1ef31..39e28bb 100644 --- a/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift +++ b/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift @@ -96,7 +96,12 @@ public class RequestIdService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.REQUEST_ID_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.REQUEST_ID_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift b/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift index 7d2f197..f1b028d 100644 --- a/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift @@ -68,7 +68,12 @@ public class ResetPasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -169,7 +174,12 @@ public class ResetPasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -269,7 +279,12 @@ public class ResetPasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift b/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift index 56158d1..0edc940 100644 --- a/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift @@ -53,7 +53,12 @@ public class SettingsService { Alamofire.request(urlString, method: .get, parameters: nil, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -146,7 +151,12 @@ public class SettingsService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -239,7 +249,12 @@ public class SettingsService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -327,7 +342,12 @@ public class SettingsService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift b/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift index 683a898..88767f9 100644 --- a/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift @@ -82,7 +82,12 @@ public class TenantService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TENANT_INFO_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TENANT_INFO_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift index fb018c6..5b77998 100644 --- a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift +++ b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift @@ -69,7 +69,12 @@ public class UserActivityService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift b/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift index 0cb9df6..ffa7d47 100644 --- a/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift @@ -56,7 +56,12 @@ public class UsersService { Alamofire.request(urlString, headers: headers).validate().responseString { response in switch response.result { - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -195,6 +200,11 @@ public class UsersService { } break case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.IMAGE_UPLOAD_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) break diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift index ae00b74..385c389 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift @@ -96,7 +96,12 @@ public class BackupcodeVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.SETUP_BACKUPCODE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.SETUP_BACKUPCODE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -196,7 +201,12 @@ public class BackupcodeVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.INITIATE_BACKUPCODE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.INITIATE_BACKUPCODE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -297,7 +307,12 @@ public class BackupcodeVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.AUTHENTICATE_BACKUPCODE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.AUTHENTICATE_BACKUPCODE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift index 262408f..213b64c 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift @@ -98,7 +98,12 @@ public class DeviceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.VALIDATE_DEVICE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.VALIDATE_DEVICE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift index 99023c2..fcce7a0 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift @@ -98,7 +98,12 @@ public class EmailVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.SETUP_EMAIL_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.SETUP_EMAIL_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -201,7 +206,12 @@ public class EmailVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ENROLL_EMAIL_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.ENROLL_EMAIL_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -302,7 +312,12 @@ public class EmailVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.INITIATE_EMAIL_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.INITIATE_EMAIL_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -402,7 +417,12 @@ public class EmailVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.AUTHENTICATE_EMAIL_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.AUTHENTICATE_EMAIL_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift index c851146..daf8f1f 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift @@ -98,7 +98,12 @@ public class FaceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.FACE_SETUP_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.FACE_SETUP_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -202,7 +207,12 @@ public class FaceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.FACE_SCANNED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.FACE_SCANNED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -344,6 +354,11 @@ public class FaceVerificationService { } break case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.FACE_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) break @@ -429,7 +444,12 @@ public class FaceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.FACE_INITIATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.FACE_INITIATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -566,6 +586,11 @@ public class FaceVerificationService { } break case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.FACE_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) break diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift index c4a65b3..9b7bfad 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift @@ -99,7 +99,12 @@ public class IVRVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.SETUP_IVR_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.SETUP_IVR_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -202,7 +207,12 @@ public class IVRVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ENROLL_IVR_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.ENROLL_IVR_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -303,7 +313,12 @@ public class IVRVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.INITIATE_IVR_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.INITIATE_IVR_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -403,7 +418,12 @@ public class IVRVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.AUTHENTICATE_IVR_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.AUTHENTICATE_IVR_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift index 0f439a1..f8061fd 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift @@ -98,7 +98,12 @@ public class PatternVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PATTERN_SETUP_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PATTERN_SETUP_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -202,7 +207,12 @@ public class PatternVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PATTERN_SCANNED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PATTERN_SCANNED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -307,7 +317,12 @@ public class PatternVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PATTERN_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PATTERN_ENROLLED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -411,7 +426,12 @@ public class PatternVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PATTERN_INITIATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PATTERN_INITIATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -512,7 +532,12 @@ public class PatternVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PATTERN_AUTHENTICATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PATTERN_AUTHENTICATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift index 759ce7c..3ed1de2 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift @@ -98,7 +98,12 @@ public class PushVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PUSH_SETUP_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PUSH_SETUP_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -202,7 +207,12 @@ public class PushVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PUSH_SCANNED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PUSH_SCANNED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -307,7 +317,12 @@ public class PushVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PUSH_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PUSH_ENROLLED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -411,7 +426,12 @@ public class PushVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PUSH_INITIATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PUSH_INITIATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -512,7 +532,12 @@ public class PushVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.PUSH_AUTHENTICATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.PUSH_AUTHENTICATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift index 3d90f0e..b298a40 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift @@ -98,7 +98,12 @@ public class SMSVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.SETUP_SMS_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.SETUP_SMS_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -201,7 +206,12 @@ public class SMSVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ENROLL_SMS_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.ENROLL_SMS_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -302,7 +312,12 @@ public class SMSVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.INITIATE_SMS_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.INITIATE_SMS_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -402,7 +417,12 @@ public class SMSVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.AUTHENTICATE_SMS_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.AUTHENTICATE_SMS_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift index 323e1bf..b160699 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift @@ -94,7 +94,7 @@ public class VerificationSettingsService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.MFA_LIST_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.MFA_LIST_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -194,7 +194,12 @@ public class VerificationSettingsService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.MFA_CONTINUE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.MFA_CONTINUE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -294,7 +299,12 @@ public class VerificationSettingsService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.MFA_CONTINUE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.MFA_CONTINUE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -387,7 +397,12 @@ public class VerificationSettingsService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.DELETE_VERIFICATION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.DELETE_VERIFICATION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -480,7 +495,12 @@ public class VerificationSettingsService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.DELETE_VERIFICATION_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.DELETE_VERIFICATION_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift index e6008fc..b0e02d8 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift @@ -98,7 +98,12 @@ public class TOTPVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOTP_SETUP_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOTP_SETUP_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -202,7 +207,12 @@ public class TOTPVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOTP_SCANNED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOTP_SCANNED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -307,7 +317,12 @@ public class TOTPVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOTP_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOTP_ENROLLED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -411,7 +426,12 @@ public class TOTPVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOTP_INITIATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOTP_INITIATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -512,7 +532,12 @@ public class TOTPVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOTP_AUTHENTICATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOTP_AUTHENTICATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift index d42bcf9..d93405e 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift @@ -98,7 +98,12 @@ public class TouchIdVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOUCHID_SETUP_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOUCHID_SETUP_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -202,7 +207,12 @@ public class TouchIdVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOUCHID_SCANNED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOUCHID_SCANNED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -308,7 +318,12 @@ public class TouchIdVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOUCHID_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOUCHID_ENROLLED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -412,7 +427,12 @@ public class TouchIdVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOUCHID_INITIATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOUCHID_INITIATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -514,7 +534,12 @@ public class TouchIdVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.TOUCHID_AUTHENTICATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.TOUCHID_AUTHENTICATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift index fd7e888..e41b789 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift @@ -99,7 +99,12 @@ public class VoiceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.VOICE_SETUP_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.VOICE_SETUP_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -203,7 +208,12 @@ public class VoiceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.VOICE_SCANNED_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.VOICE_SCANNED_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -342,6 +352,11 @@ public class VoiceVerificationService { } break case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.VOICE_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) break @@ -427,7 +442,12 @@ public class VoiceVerificationService { callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.VOICE_INITIATE_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.VOICE_INITIATE_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) } break - case .failure: + case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } if (response.data != nil) { let jsonString = String(decoding: response.data!, as: UTF8.self) let decoder = JSONDecoder() @@ -561,6 +581,11 @@ public class VoiceVerificationService { } break case .failure(let error): + if error._code == NSURLErrorTimedOut { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } // return failure callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.VOICE_ENROLLED_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) break diff --git a/Example/Cidaas/ViewController.swift b/Example/Cidaas/ViewController.swift index a5150ca..3ab0bd2 100644 --- a/Example/Cidaas/ViewController.swift +++ b/Example/Cidaas/ViewController.swift @@ -30,55 +30,8 @@ class ViewController: UIViewController, WKNavigationDelegate, CidaasLoaderDelega CidaasFacebook.shared.delegate = self CidaasGoogle.shared.delegate = self + getRequestId() -// cidaasView.loginWithEmbeddedBrowser(delegate: self) { -// switch $0 { -// case .success(let result): -// let alert = UIAlertController(title: "Alert", message: result.data.access_token, preferredStyle: .alert) -// alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in -// switch action.style{ -// case .default: -// print("default") -// self.logout(accessToken: result.data.access_token) -// case .cancel: -// print("cancel") -// -// case .destructive: -// print("destructive") -// }})) -// self.present(alert, animated: true, completion: nil) -// -// break -// case .failure(let errorResponse): -// print(errorResponse.errorMessage) -// -// break -// } -// } - -// let gl = CidaasGoogle.shared -// gl.login(viewType: "login") { -// switch $0 { -// case .success(let successResponse): -// let alert = UIAlertController(title: "Alert", message: successResponse.data.access_token, preferredStyle: .alert) -// alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in -// switch action.style{ -// case .default: -// print("default") -// -// case .cancel: -// print("cancel") -// -// case .destructive: -// print("destructive") -// }})) -// self.present(alert, animated: true, completion: nil) -// break -// case .failure(let errorResponse): -// print(errorResponse) -// break -// } -// } } func showLoader() { @@ -136,7 +89,7 @@ class ViewController: UIViewController, WKNavigationDelegate, CidaasLoaderDelega switch $0 { case .success(let requestIdSuccessResponse): print(requestIdSuccessResponse.data.requestId) - self.loginWithBrowser() +// self.loginWithBrowser() break case .failure(let requestIdFailureResponse): print(requestIdFailureResponse.errorMessage) From af3fa801d3e47022cc295caecd449d4425306ba2 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 19 Feb 2019 14:43:18 +0530 Subject: [PATCH 08/14] error code for touch id changes --- Cidaas/Classes/Core/Views/Cidaas.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index 9d214a9..ac52dfe 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -1181,6 +1181,9 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = res_errorCode ?? WebAuthError.shared.errorCode + // return failure callback DispatchQueue.main.async { @@ -1194,6 +1197,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { @@ -1259,6 +1264,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = res_errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { @@ -1272,6 +1279,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { @@ -2073,6 +2082,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = res_errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { @@ -2086,6 +2097,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { From c6f45f027a0480a8bb4be1b922563c1ac8eec658 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 19 Feb 2019 17:46:30 +0530 Subject: [PATCH 09/14] error code fixes --- Cidaas/Classes/Core/Views/Cidaas.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index ac52dfe..1d8c04d 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -442,10 +442,10 @@ public class Cidaas { response.success = success_pass response.status = code_pass ?? 400 response.message = message_pass ?? "Authentication Failed" - } - DispatchQueue.main.async { - callback(response) - return + DispatchQueue.main.async { + callback(response) + return + } } }) } @@ -2322,6 +2322,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = res_errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = res_errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = res_errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { @@ -2335,6 +2337,8 @@ public class Cidaas { let error = WebAuthError.shared error.errorMessage = errorMessage ?? WebAuthError.shared.errorMessage error.errorCode = errorCode ?? WebAuthError.shared.errorCode + let errorResponse = error.error + errorResponse.error.code = errorCode ?? WebAuthError.shared.errorCode // return failure callback DispatchQueue.main.async { From eb459075c8d93f2e5347037949fecacec0e33f5a Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Wed, 20 Feb 2019 13:18:34 +0530 Subject: [PATCH 10/14] Network error code changed based onNSURL Error Domain --- .../Repository/AccessToken/AccessTokenService.swift | 6 +++--- .../AccountVerificationService.swift | 6 +++--- .../Changepassword/ChangePasswordService.swift | 2 +- .../Services/Repository/Client/ClientService.swift | 2 +- .../Services/Repository/Consent/ConsentService.swift | 8 ++++---- .../Deduplication/DeduplicationService.swift | 6 +++--- .../Repository/DocumentScan/DocumentScanService.swift | 2 +- .../Repository/LinkUnlink/LinkUnlinkService.swift | 6 +++--- .../Services/Repository/Location/LocationService.swift | 8 ++++---- .../Core/Services/Repository/Login/LoginService.swift | 2 +- .../Repository/Registration/RegistrationService.swift | 6 +++--- .../Repository/RequestId/RequestIdService.swift | 2 +- .../Resetpassword/ResetPasswordService.swift | 6 +++--- .../Services/Repository/Settings/SettingsService.swift | 8 ++++---- .../Services/Repository/Tenant/TenantService.swift | 2 +- .../UserActivities/UserActivityService.swift | 2 +- .../Core/Services/Repository/Users/UsersService.swift | 4 ++-- .../Backupcode/BackupcodeVerificationService.swift | 6 +++--- .../Device/DeviceVerificationService.swift | 2 +- .../Verification/Email/EmailVerificationService.swift | 8 ++++---- .../Verification/Face/FaceVerificationService.swift | 10 +++++----- .../Verification/IVR/IVRVerificationService.swift | 8 ++++---- .../Pattern/PatternVerificationService.swift | 10 +++++----- .../Verification/Push/PushVerificationService.swift | 10 +++++----- .../Verification/SMS/SMSVerificationService.swift | 8 ++++---- .../Settings/VerificationSettingsService.swift | 8 ++++---- .../Verification/TOTP/TOTPVerificationService.swift | 10 +++++----- .../Touch/TouchIdVerificationService.swift | 10 +++++----- .../Verification/Voice/VoiceVerificationService.swift | 10 +++++----- 29 files changed, 89 insertions(+), 89 deletions(-) diff --git a/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift b/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift index 49e9368..b19b5d3 100644 --- a/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift +++ b/Cidaas/Classes/Core/Services/Repository/AccessToken/AccessTokenService.swift @@ -66,7 +66,7 @@ public class AccessTokenService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -140,7 +140,7 @@ public class AccessTokenService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -216,7 +216,7 @@ public class AccessTokenService { Alamofire.request(urlString, method: .get, headers: headers).validate(statusCode: 200..<308).responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift index 5af224e..ffb6936 100644 --- a/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/AccountVerification/AccountVerificationService.swift @@ -69,7 +69,7 @@ public class AccountVerificationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -174,7 +174,7 @@ public class AccountVerificationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -266,7 +266,7 @@ public class AccountVerificationService { Alamofire.request(urlString, method: .get, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift b/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift index f250470..d8fdc85 100644 --- a/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Changepassword/ChangePasswordService.swift @@ -72,7 +72,7 @@ public class ChangePasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift b/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift index 4fcd1bc..389cebd 100644 --- a/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Client/ClientService.swift @@ -83,7 +83,7 @@ public class ClientService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift b/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift index 1e1fefb..f649531 100644 --- a/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Consent/ConsentService.swift @@ -87,7 +87,7 @@ public class ConsentService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -185,7 +185,7 @@ public class ConsentService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -295,7 +295,7 @@ public class ConsentService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -400,7 +400,7 @@ public class ConsentService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift b/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift index 902954d..8741a10 100644 --- a/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Deduplication/DeduplicationService.swift @@ -56,7 +56,7 @@ public class DeduplicationService { Alamofire.request(urlString, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -148,7 +148,7 @@ public class DeduplicationService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -255,7 +255,7 @@ public class DeduplicationService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift b/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift index 69966c6..2f156ae 100644 --- a/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift +++ b/Cidaas/Classes/Core/Services/Repository/DocumentScan/DocumentScanService.swift @@ -116,7 +116,7 @@ public class DocumentScanService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift b/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift index 6cfb531..7af9a72 100644 --- a/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift +++ b/Cidaas/Classes/Core/Services/Repository/LinkUnlink/LinkUnlinkService.swift @@ -62,7 +62,7 @@ public class LinkUnlinkService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -155,7 +155,7 @@ public class LinkUnlinkService { Alamofire.request(urlString, method: .get, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -248,7 +248,7 @@ public class LinkUnlinkService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift b/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift index 95fb725..5a84168 100644 --- a/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Location/LocationService.swift @@ -56,7 +56,7 @@ public class LocationService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -163,7 +163,7 @@ public class LocationService { headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -255,7 +255,7 @@ public class LocationService { Alamofire.request(urlString, method: .get, parameters: nil, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -362,7 +362,7 @@ public class LocationService { headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift b/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift index 2225c7d..a8c204a 100644 --- a/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Login/LoginService.swift @@ -98,7 +98,7 @@ public class LoginService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift b/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift index 9d2bda5..786da90 100644 --- a/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Registration/RegistrationService.swift @@ -83,7 +83,7 @@ public class RegistrationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -190,7 +190,7 @@ public class RegistrationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -297,7 +297,7 @@ public class RegistrationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift b/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift index 39e28bb..68b78cf 100644 --- a/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift +++ b/Cidaas/Classes/Core/Services/Repository/RequestId/RequestIdService.swift @@ -97,7 +97,7 @@ public class RequestIdService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift b/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift index f1b028d..484b410 100644 --- a/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Resetpassword/ResetPasswordService.swift @@ -69,7 +69,7 @@ public class ResetPasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -175,7 +175,7 @@ public class ResetPasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -280,7 +280,7 @@ public class ResetPasswordService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift b/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift index 0edc940..ef7d30c 100644 --- a/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Settings/SettingsService.swift @@ -54,7 +54,7 @@ public class SettingsService { Alamofire.request(urlString, method: .get, parameters: nil, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -152,7 +152,7 @@ public class SettingsService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -250,7 +250,7 @@ public class SettingsService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -343,7 +343,7 @@ public class SettingsService { Alamofire.request(urlString, method: .post, parameters: nil, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift b/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift index 88767f9..90b31db 100644 --- a/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Tenant/TenantService.swift @@ -83,7 +83,7 @@ public class TenantService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift index 5b77998..9d1e2ae 100644 --- a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift +++ b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift @@ -70,7 +70,7 @@ public class UserActivityService { Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift b/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift index ffa7d47..315b2f4 100644 --- a/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Users/UsersService.swift @@ -57,7 +57,7 @@ public class UsersService { Alamofire.request(urlString, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -200,7 +200,7 @@ public class UsersService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift index 385c389..9607aed 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Backupcode/BackupcodeVerificationService.swift @@ -97,7 +97,7 @@ public class BackupcodeVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -202,7 +202,7 @@ public class BackupcodeVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -308,7 +308,7 @@ public class BackupcodeVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift index 213b64c..3134966 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Device/DeviceVerificationService.swift @@ -99,7 +99,7 @@ public class DeviceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift index fcce7a0..a057f59 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Email/EmailVerificationService.swift @@ -99,7 +99,7 @@ public class EmailVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -207,7 +207,7 @@ public class EmailVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -313,7 +313,7 @@ public class EmailVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -418,7 +418,7 @@ public class EmailVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift index daf8f1f..3164b52 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift @@ -99,7 +99,7 @@ public class FaceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -208,7 +208,7 @@ public class FaceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -354,7 +354,7 @@ public class FaceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -445,7 +445,7 @@ public class FaceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -586,7 +586,7 @@ public class FaceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift index 9b7bfad..5dcced3 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/IVR/IVRVerificationService.swift @@ -100,7 +100,7 @@ public class IVRVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -208,7 +208,7 @@ public class IVRVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -314,7 +314,7 @@ public class IVRVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -419,7 +419,7 @@ public class IVRVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift index f8061fd..7f06c74 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Pattern/PatternVerificationService.swift @@ -99,7 +99,7 @@ public class PatternVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -208,7 +208,7 @@ public class PatternVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -318,7 +318,7 @@ public class PatternVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -427,7 +427,7 @@ public class PatternVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -533,7 +533,7 @@ public class PatternVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift index 3ed1de2..5afcd19 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Push/PushVerificationService.swift @@ -99,7 +99,7 @@ public class PushVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -208,7 +208,7 @@ public class PushVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -318,7 +318,7 @@ public class PushVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -427,7 +427,7 @@ public class PushVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -533,7 +533,7 @@ public class PushVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift index b298a40..7625401 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/SMS/SMSVerificationService.swift @@ -99,7 +99,7 @@ public class SMSVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -207,7 +207,7 @@ public class SMSVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -313,7 +313,7 @@ public class SMSVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -418,7 +418,7 @@ public class SMSVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift index b160699..c599904 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Settings/VerificationSettingsService.swift @@ -195,7 +195,7 @@ public class VerificationSettingsService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -300,7 +300,7 @@ public class VerificationSettingsService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -398,7 +398,7 @@ public class VerificationSettingsService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -496,7 +496,7 @@ public class VerificationSettingsService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift index b0e02d8..120f1fc 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/TOTP/TOTPVerificationService.swift @@ -99,7 +99,7 @@ public class TOTPVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -208,7 +208,7 @@ public class TOTPVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -318,7 +318,7 @@ public class TOTPVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -427,7 +427,7 @@ public class TOTPVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -533,7 +533,7 @@ public class TOTPVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift index d93405e..37f4d39 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Touch/TouchIdVerificationService.swift @@ -99,7 +99,7 @@ public class TouchIdVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -208,7 +208,7 @@ public class TouchIdVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -319,7 +319,7 @@ public class TouchIdVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -428,7 +428,7 @@ public class TouchIdVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -535,7 +535,7 @@ public class TouchIdVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return diff --git a/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift b/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift index e41b789..937363b 100644 --- a/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift +++ b/Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift @@ -100,7 +100,7 @@ public class VoiceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -209,7 +209,7 @@ public class VoiceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -352,7 +352,7 @@ public class VoiceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -443,7 +443,7 @@ public class VoiceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return @@ -581,7 +581,7 @@ public class VoiceVerificationService { } break case .failure(let error): - if error._code == NSURLErrorTimedOut { + if error._domain == NSURLErrorDomain { // return failure callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) return From 52368bf23f2db365edfc7717e80e78104c0cef98 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 12 Mar 2019 11:40:08 +0530 Subject: [PATCH 11/14] touch id crash fixes --- Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift | 11 +++++++++-- .../Entity/Settings/PushNotificationEntity.swift | 12 ++++++++++++ Example/Cidaas/Cidaas.plist | 6 +++--- README.md | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift index ad61121..ddfde76 100644 --- a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift +++ b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift @@ -91,6 +91,11 @@ public class TouchID { public func checkIfPasscodeAvailable(invalidateAuthenticationContext: Bool, callback: @escaping (Bool, String?, Int32?)->()) { if invalidateAuthenticationContext == true { self.authenticatedContext.invalidate() + + DispatchQueue.main.async { + callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) + return + } } if authenticatedContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) { @@ -106,8 +111,10 @@ public class TouchID { } break case LAError.invalidContext.rawValue: - self.authenticatedContext = LAContext() - self.checkIfPasscodeAvailable(invalidateAuthenticationContext: false, callback: callback) + if (!invalidateAuthenticationContext) { + self.authenticatedContext = LAContext() + self.checkIfPasscodeAvailable(invalidateAuthenticationContext: false, callback: callback) + } DispatchQueue.main.async { callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) } diff --git a/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift b/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift index a130401..c5662c7 100644 --- a/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift +++ b/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift @@ -17,6 +17,12 @@ public class PushNotificationEntity : Codable { public var address : PushAddress = PushAddress() public var deviceInfo : PushDeviceInfo = PushDeviceInfo() + public var dataShareType: String = "" + public var baseurl: String = "" + public var client_id: String = "" + public var redirect_url: String = "" + public var user_device_id: String = "" + public init() { } @@ -31,6 +37,12 @@ public class PushNotificationEntity : Codable { self.randomNumbers = try container.decodeIfPresent(String.self, forKey: .randomNumbers) ?? "" self.address = try container.decodeIfPresent(PushAddress.self, forKey: .address) ?? PushAddress() self.deviceInfo = try container.decodeIfPresent(PushDeviceInfo.self, forKey: .deviceInfo) ?? PushDeviceInfo() + + self.dataShareType = try container.decodeIfPresent(String.self, forKey: .dataShareType) ?? "" + self.baseurl = try container.decodeIfPresent(String.self, forKey: .baseurl) ?? "" + self.client_id = try container.decodeIfPresent(String.self, forKey: .client_id) ?? "" + self.user_device_id = try container.decodeIfPresent(String.self, forKey: .user_device_id) ?? "" + self.redirect_url = try container.decodeIfPresent(String.self, forKey: .redirect_url) ?? "" } } diff --git a/Example/Cidaas/Cidaas.plist b/Example/Cidaas/Cidaas.plist index 507720f..d4b9b58 100644 --- a/Example/Cidaas/Cidaas.plist +++ b/Example/Cidaas/Cidaas.plist @@ -3,10 +3,10 @@ DomainURL - your_base_url + https://nightlybuild.cidaas.de ClientId - your_client_id + f27c8ca3-257e-489d-b28e-5f9e1abbe94 RedirectURL - your_redirect_url + https://nightlybuild.cidaas.de/login-srv/social/callback/gothaer diff --git a/README.md b/README.md index f5acef8..1e1c590 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ A sample plist file would look like this : The following sections will help you to generate some of the information that is needed for plist. #### Getting Client Id and urls -You can get this by creating your App in App settings section of cidaas Admin portal. Once you select the right scope and application type, and fill in all mandatory fields, you can use the generated Client ID and redirect URLs. +When you are integrating your own Business App with, you may want to modularize the interactions and attributes. There are like Scope, Roles, Grant-Types, re-direct URLs etc., that you may want to group into one configuration/settings. This can be done by creating App or Client. #### Initialization From 1f6c684ce2f1f450650aab5e74650706be54b624 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 12 Mar 2019 14:11:32 +0530 Subject: [PATCH 12/14] get login information --- .../UserActivityController.swift | 72 ++++++++++++ .../Core/Helpers/Enums/WebAuthErrorCode.swift | 2 + .../Core/Helpers/General/URLHelper.swift | 5 + .../Core/Helpers/Locale/StringsHelper.swift | 2 + .../Settings/PushNotificationEntity.swift | 11 +- .../UserActivities/UserLoginInfoEntity.swift | 23 ++++ .../UserLoginInfoResponseEntity.swift | 54 +++++++++ .../UserActivities/UserActivityService.swift | 106 ++++++++++++++++++ Cidaas/Classes/Core/Views/Cidaas.swift | 28 +++++ Example/Cidaas/Cidaas.plist | 6 +- 10 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoEntity.swift create mode 100644 Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoResponseEntity.swift diff --git a/Cidaas/Classes/Core/Controllers/Repository/UserActivities/UserActivityController.swift b/Cidaas/Classes/Core/Controllers/Repository/UserActivities/UserActivityController.swift index db8e8af..81d319e 100644 --- a/Cidaas/Classes/Core/Controllers/Repository/UserActivities/UserActivityController.swift +++ b/Cidaas/Classes/Core/Controllers/Repository/UserActivities/UserActivityController.swift @@ -89,4 +89,76 @@ public class UserActivityController { } } } + + // get user login info + public func getUserLoginInformation(userInfo: UserLoginInfoEntity, properties: Dictionary, callback: @escaping(Result) -> Void) { + // null check + if properties["DomainURL"] == "" || properties["DomainURL"] == nil { + let error = WebAuthError.shared.propertyMissingException() + // log error + let loggerMessage = "Read properties failure : " + "Error Code - " + String(describing: error.errorCode) + ", Error Message - " + error.errorMessage + ", Status Code - " + String(describing: error.statusCode) + logw(loggerMessage, cname: "cidaas-sdk-error-log") + + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + + // validating fields + if (userInfo.sub == "" && userInfo.verificationType == "") { + let error = WebAuthError.shared.propertyMissingException() + error.errorMessage = "sub or verificationType must not be empty" + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + + // get access token from sub + AccessTokenController.shared.getAccessToken(sub: userInfo.sub) { + switch $0 { + case .failure(let error): + // log error + let loggerMessage = "Access token failure : " + "Error Code - " + String(describing: error.errorCode) + ", Error Message - " + error.errorMessage + ", Status Code - " + String(describing: error.statusCode) + logw(loggerMessage, cname: "cidaas-sdk-error-log") + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + case .success(let tokenResponse): + // log success + let loggerMessage = "Access Token success : " + "Access Token - " + String(describing: tokenResponse.data.access_token) + logw(loggerMessage, cname: "cidaas-sdk-success-log") + + // call get login user info service + UserActivityService.shared.getUserLoginInformation(accessToken: tokenResponse.data.access_token, userInfo: userInfo, properties: properties) { + switch $0 { + case .failure(let error): + // log error + let loggerMessage = "User Login Info service failure : " + "Error Code - " + String(describing: error.errorCode) + ", Error Message - " + error.errorMessage + ", Status Code - " + String(describing: error.statusCode) + logw(loggerMessage, cname: "cidaas-sdk-error-log") + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + case .success(let tenantInfoResponse): + // log success + let loggerMessage = "User User Login Info service success : " + "Count - " + String(describing: tenantInfoResponse.data.count) + logw(loggerMessage, cname: "cidaas-sdk-success-log") + + // return callback + DispatchQueue.main.async { + callback(Result.success(result: tenantInfoResponse)) + } + } + } + + } + } + } } diff --git a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift index 32d92e2..681c97e 100644 --- a/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift +++ b/Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift @@ -228,4 +228,6 @@ public enum WebAuthErrorCode : Int32 { case TOUCHID_NOT_INTERACTIVE = 10188 case NETWORK_TIMEOUT = 10189 + + case USER_LOGIN_INFO_SERVICE_FAILURE = 10190 } diff --git a/Cidaas/Classes/Core/Helpers/General/URLHelper.swift b/Cidaas/Classes/Core/Helpers/General/URLHelper.swift index e1046d1..45ecdce 100644 --- a/Cidaas/Classes/Core/Helpers/General/URLHelper.swift +++ b/Cidaas/Classes/Core/Helpers/General/URLHelper.swift @@ -105,6 +105,7 @@ public class URLHelper { public var documentScanURL = "/access-control-srv/ocr/validate" public var userActivityURL = "/useractivity-srv/latestactivity" + public var userLoginInfoURL = "/verification-srv/verificationstatus/status/search/sdk" public var updateUserURL = "/users-srv/user/profile" public var imageUploadURL = "/image-srv/profile/upload" public var linkUserURL = "/users-srv/user/linkaccount" @@ -441,6 +442,10 @@ public class URLHelper { return userActivityURL } + public func getUserLoginInfoURL() -> String { + return userLoginInfoURL + } + public func getDeduplicationDetailsURL(track_id: String) -> String { return deduplicationDetails + "/" + track_id } diff --git a/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift b/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift index 101f68d..80f9f5c 100644 --- a/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift +++ b/Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift @@ -224,4 +224,6 @@ public class StringsHelper { public var UPDATE_FCM_SERVICE_FAILURE: String = "Update FCM token service failure" public var PENDING_NOTIFICATION_LIST_SERVICE_FAILURE: String = "Pending notification service failure" public var NETWORK_TIMEOUT: String = "Network Timeout" + + public var USER_LOGIN_INFO_SERVICE_FAILURE = "User login information service failure" } diff --git a/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift b/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift index c5662c7..3d48a86 100644 --- a/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift +++ b/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift @@ -54,6 +54,10 @@ public class PushDeviceInfo : Codable { public var deviceMake : String = "" public var deviceModel : String = "" public var userAgent : String = "" + public var sub: String = "" + public var ipAddress: String = "" + public var pushNotificationId: String = "" + public var deviceId: String = "" public init() { @@ -67,6 +71,9 @@ public class PushDeviceInfo : Codable { self.deviceMake = try container.decodeIfPresent(String.self, forKey: .deviceMake) ?? "" self.deviceModel = try container.decodeIfPresent(String.self, forKey: .deviceModel) ?? "" self.userAgent = try container.decodeIfPresent(String.self, forKey: .userAgent) ?? "" + self.sub = try container.decodeIfPresent(String.self, forKey: .sub) ?? "" + self.ipAddress = try container.decodeIfPresent(String.self, forKey: .ipAddress) ?? "" + self.pushNotificationId = try container.decodeIfPresent(String.self, forKey: .pushNotificationId) ?? "" } } @@ -85,7 +92,7 @@ public class PushAddress : Codable { public var street: String = "" public var houseNo: String = "" public var resolver: String = "" - + public var elevation: Int32 = 0 public init() { @@ -107,6 +114,8 @@ public class PushAddress : Codable { self.street = try container.decodeIfPresent(String.self, forKey: .street) ?? "" self.houseNo = try container.decodeIfPresent(String.self, forKey: .houseNo) ?? "" self.resolver = try container.decodeIfPresent(String.self, forKey: .resolver) ?? "" + self.elevation = try container.decodeIfPresent(Int32.self, forKey: .elevation) ?? 0 + } } diff --git a/Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoEntity.swift b/Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoEntity.swift new file mode 100644 index 0000000..07b1d66 --- /dev/null +++ b/Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoEntity.swift @@ -0,0 +1,23 @@ +// +// UserLoginInfoEntity.swift +// Cidaas +// +// Created by ganesh on 12/03/19. +// + +import Foundation + +public class UserLoginInfoEntity : Codable { + // properties + public var sub: String = "" + public var skip: Int16 = 0 + public var take: Int16 = 0 + public var verificationType: String = "" + public var startDate: String = "" + public var endDate: String = "" + + // Constructors + public init() { + + } +} diff --git a/Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoResponseEntity.swift b/Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoResponseEntity.swift new file mode 100644 index 0000000..9325fea --- /dev/null +++ b/Cidaas/Classes/Core/Services/Entity/UserActivities/UserLoginInfoResponseEntity.swift @@ -0,0 +1,54 @@ +// +// UserLoginInfoResponseEntity.swift +// Cidaas +// +// Created by ganesh on 12/03/19. +// + +import Foundation + +public class UserLoginInfoResponseEntity : Codable { + // properties + public var success: Bool = false + public var status: Int16 = 400 + public var data: [UserLoginInfoResponseDataEntity] = [] + + // Constructors + public init() { + + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.success = try container.decodeIfPresent(Bool.self, forKey: .success) ?? false + self.status = try container.decodeIfPresent(Int16.self, forKey: .status) ?? 400 + self.data = try container.decodeIfPresent([UserLoginInfoResponseDataEntity].self, forKey: .data) ?? [] + } +} + +public class UserLoginInfoResponseDataEntity : Codable { + // properties + public var _id: String = "" + public var currentState: String = "" + public var sub: String = "" + public var verificationType: String = "" + public var time: String = "" + public var deviceInfo: PushDeviceInfo = PushDeviceInfo() + public var address: PushAddress = PushAddress() + + // Constructors + public init() { + + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self._id = try container.decodeIfPresent(String.self, forKey: ._id) ?? "" + self.currentState = try container.decodeIfPresent(String.self, forKey: .currentState) ?? "" + self.sub = try container.decodeIfPresent(String.self, forKey: .sub) ?? "" + self.verificationType = try container.decodeIfPresent(String.self, forKey: .verificationType) ?? "" + self.time = try container.decodeIfPresent(String.self, forKey: .time) ?? "" + self.deviceInfo = try container.decodeIfPresent(PushDeviceInfo.self, forKey: .deviceInfo) ?? PushDeviceInfo() + self.address = try container.decodeIfPresent(PushAddress.self, forKey: .address) ?? PushAddress() + } +} diff --git a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift index 9d1e2ae..06cd800 100644 --- a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift +++ b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift @@ -125,4 +125,110 @@ public class UserActivityService { } } } + + // get login user activities + public func getUserLoginInformation(accessToken : String, userInfo: UserLoginInfoEntity, properties : Dictionary, callback: @escaping (Result) -> Void) { + + // local variables + var headers : HTTPHeaders + var urlString : String + var baseURL : String + + // get device information + let deviceInfoEntity = DBHelper.shared.getDeviceInfo() + + // construct headers + headers = [ + "User-Agent": CidaasUserAgentBuilder.shared.UAString(), + "lat": location.0, + "lon": location.1, + "access_token": accessToken, + "deviceId" : deviceInfoEntity.deviceId, + "deviceMake" : deviceInfoEntity.deviceMake, + "deviceModel" : deviceInfoEntity.deviceModel, + "deviceVersion" : deviceInfoEntity.deviceVersion + ] + + // construct body params + var bodyParams = Dictionary() + + do { + let encoder = JSONEncoder() + let data = try encoder.encode(userInfo) + bodyParams = try! JSONSerialization.jsonObject(with: data, options: []) as? Dictionary ?? Dictionary() + } + catch(_) { + callback(Result.failure(error: WebAuthError.shared.conversionException())) + return + } + + // assign base url + baseURL = (properties["DomainURL"]) ?? "" + + if baseURL == "" { + callback(Result.failure(error: WebAuthError.shared.propertyMissingException())) + return + } + + // construct url + urlString = baseURL + URLHelper.shared.getUserLoginInfoURL() + + Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in + switch response.result { + case .failure(let error): + if error._domain == NSURLErrorDomain { + // return failure + callback(Result.failure(error: WebAuthError.shared.netWorkTimeoutException())) + return + } + if (response.data != nil) { + let jsonString = String(decoding: response.data!, as: UTF8.self) + let decoder = JSONDecoder() + do { + let data = jsonString.data(using: .utf8)! + // decode the json data to object + let errorResponseEntity = try decoder.decode(ErrorResponseEntity.self, from: data) + + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.USER_LOGIN_INFO_SERVICE_FAILURE.rawValue, errorMessage: errorResponseEntity.error.error, statusCode: Int(errorResponseEntity.status), error: errorResponseEntity))) + } + catch(let error) { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.USER_LOGIN_INFO_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400))) + } + } + else { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.USER_LOGIN_INFO_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.USER_LOGIN_INFO_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) + } + return + case .success: + if response.response?.statusCode == 200 { + if let jsonString = response.result.value { + let decoder = JSONDecoder() + do { + let data = jsonString.data(using: .utf8)! + let userInfoEntity = try decoder.decode(UserLoginInfoResponseEntity.self, from: data) + // return success + callback(Result.success(result: userInfoEntity)) + } + catch { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.ERROR_JSON_PARSING.rawValue, errorMessage: StringsHelper.shared.ERROR_JSON_PARSING, statusCode: HttpStatusCode.DEFAULT.rawValue))) + return + } + } + else { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.USER_LOGIN_INFO_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.USER_LOGIN_INFO_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) + } + } + else { + // return failure + callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.USER_LOGIN_INFO_SERVICE_FAILURE.rawValue, errorMessage: StringsHelper.shared.USER_LOGIN_INFO_SERVICE_FAILURE, statusCode: response.response?.statusCode ?? 400))) + break + } + } + } + } } diff --git a/Cidaas/Classes/Core/Views/Cidaas.swift b/Cidaas/Classes/Core/Views/Cidaas.swift index 1d8c04d..faee244 100644 --- a/Cidaas/Classes/Core/Views/Cidaas.swift +++ b/Cidaas/Classes/Core/Views/Cidaas.swift @@ -2815,6 +2815,34 @@ public class Cidaas { } } +// -------------------------------------------------------------------------------------------------- // + + // get user login info from plist + // 1. Read properties from file + // 2. Call getUserActivity method + // 3. Maintain logs based on flags + + public func getUserLoginInformation(userInfo: UserLoginInfoEntity, callback: @escaping(Result) -> Void) { + + let savedProp = DBHelper.shared.getPropertyFile() + if (savedProp != nil) { + UserActivityController.shared.getUserLoginInformation(userInfo: userInfo, properties: savedProp!, callback: callback) + } + else { + // log error + let loggerMessage = "Read properties file failure : " + "Error Code - 10001, Error Message - File not found, Status Code - 404" + logw(loggerMessage, cname: "cidaas-sdk-error-log") + + let error = WebAuthError.shared.fileNotFoundException() + + // return failure callback + DispatchQueue.main.async { + callback(Result.failure(error: error)) + } + return + } + } + // -------------------------------------------------------------------------------------------------- // // update user from plist diff --git a/Example/Cidaas/Cidaas.plist b/Example/Cidaas/Cidaas.plist index d4b9b58..0b3e604 100644 --- a/Example/Cidaas/Cidaas.plist +++ b/Example/Cidaas/Cidaas.plist @@ -3,10 +3,10 @@ DomainURL - https://nightlybuild.cidaas.de + {{baseurl}} ClientId - f27c8ca3-257e-489d-b28e-5f9e1abbe94 + {{client_id}} RedirectURL - https://nightlybuild.cidaas.de/login-srv/social/callback/gothaer + {{redirect_uri}} From 766afdb83f3309e0cf9a85ac350c3d599875a933 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Tue, 19 Mar 2019 12:17:14 +0530 Subject: [PATCH 13/14] Touch ID crash fixes --- .../Core/Helpers/Biometrics/TouchID.swift | 126 +++++++++--------- .../Settings/PushNotificationEntity.swift | 1 + 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift index ddfde76..426804b 100644 --- a/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift +++ b/Cidaas/Classes/Core/Helpers/Biometrics/TouchID.swift @@ -98,72 +98,74 @@ public class TouchID { } } - if authenticatedContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) { - DispatchQueue.main.async { - callback(true, nil, nil) - } - } else { - switch error!.code { - case LAError.touchIDNotAvailable.rawValue: - DispatchQueue.main.async { - callback(false, "TouchId not available", WebAuthErrorCode.TOUCHID_NOT_AVAILABLE.rawValue) - } - break - case LAError.invalidContext.rawValue: - if (!invalidateAuthenticationContext) { - self.authenticatedContext = LAContext() - self.checkIfPasscodeAvailable(invalidateAuthenticationContext: false, callback: callback) - } - DispatchQueue.main.async { - callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) - } - break - case LAError.touchIDNotEnrolled.rawValue: - DispatchQueue.main.async { - callback(false, "TouchId not enrolled", WebAuthErrorCode.TOUCHID_NOT_ENROLLED.rawValue) - } - break - case LAError.passcodeNotSet.rawValue: + if authenticatedContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) { DispatchQueue.main.async { - callback(false, "Passcode not configured", WebAuthErrorCode.TOUCH_ID_PASSCODE_NOT_CONFIGURED.rawValue) - } - break - case LAError.authenticationFailed.rawValue: - DispatchQueue.main.async { - callback(false, "Invalid authentication", WebAuthErrorCode.TOUCH_ID_INVALID_AUTHENTICATION.rawValue) - } - break - case LAError.appCancel.rawValue: - DispatchQueue.main.async { - callback(false, "App cancelled", WebAuthErrorCode.TOUCH_ID_APP_CANCELLED.rawValue) - } - break - case LAError.systemCancel.rawValue: - DispatchQueue.main.async { - callback(false, "System cancelled", WebAuthErrorCode.TOUCH_ID_SYSTEM_CANCELLED.rawValue) - } - break - case LAError.userCancel.rawValue: - DispatchQueue.main.async { - callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) - } - break - case LAError.touchIDLockout.rawValue: - DispatchQueue.main.async { - callback(false, "TouchId locked", WebAuthErrorCode.TOUCHID_LOCKED.rawValue) - } - break - case LAError.userFallback.rawValue: - DispatchQueue.main.async { - callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + callback(true, nil, nil) } - break - default: - DispatchQueue.main.async { - callback(false, "Error occured", WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + } + else { + switch error!.code { + case LAError.touchIDNotAvailable.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not available", WebAuthErrorCode.TOUCHID_NOT_AVAILABLE.rawValue) + } + break + case LAError.invalidContext.rawValue: + if (!invalidateAuthenticationContext) { + self.authenticatedContext = LAContext() + self.checkIfPasscodeAvailable(invalidateAuthenticationContext: false, callback: callback) + } + DispatchQueue.main.async { + callback(false, "Invalid context", WebAuthErrorCode.TOUCHID_INVALID_CONTEXT.rawValue) + } + break + case LAError.touchIDNotEnrolled.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId not enrolled", WebAuthErrorCode.TOUCHID_NOT_ENROLLED.rawValue) + } + break + case LAError.passcodeNotSet.rawValue: + DispatchQueue.main.async { + callback(false, "Passcode not configured", WebAuthErrorCode.TOUCH_ID_PASSCODE_NOT_CONFIGURED.rawValue) + } + break + case LAError.authenticationFailed.rawValue: + DispatchQueue.main.async { + callback(false, "Invalid authentication", WebAuthErrorCode.TOUCH_ID_INVALID_AUTHENTICATION.rawValue) + } + break + case LAError.appCancel.rawValue: + DispatchQueue.main.async { + callback(false, "App cancelled", WebAuthErrorCode.TOUCH_ID_APP_CANCELLED.rawValue) + } + break + case LAError.systemCancel.rawValue: + DispatchQueue.main.async { + callback(false, "System cancelled", WebAuthErrorCode.TOUCH_ID_SYSTEM_CANCELLED.rawValue) + } + break + case LAError.userCancel.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + case LAError.touchIDLockout.rawValue: + DispatchQueue.main.async { + callback(false, "TouchId locked", WebAuthErrorCode.TOUCHID_LOCKED.rawValue) + } + break + case LAError.userFallback.rawValue: + DispatchQueue.main.async { + callback(false, "User cancelled", WebAuthErrorCode.TOUCH_ID_USER_CANCELLED.rawValue) + } + break + default: + DispatchQueue.main.async { + callback(false, "Error occured", WebAuthErrorCode.TOUCHID_DEFAULT_ERROR.rawValue) + } + break } - break } } } diff --git a/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift b/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift index 3d48a86..ecb5b66 100644 --- a/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift +++ b/Cidaas/Classes/Core/Services/Entity/Settings/PushNotificationEntity.swift @@ -23,6 +23,7 @@ public class PushNotificationEntity : Codable { public var redirect_url: String = "" public var user_device_id: String = "" + public init() { } From 7842717dfe07d3f362e64e2c69e5535ea82e8ae8 Mon Sep 17 00:00:00 2001 From: "ganesh.kumar" Date: Wed, 27 Mar 2019 11:48:54 +0530 Subject: [PATCH 14/14] encode URL --- .../Repository/UserActivities/UserActivityService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift index 06cd800..6e311f8 100644 --- a/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift +++ b/Cidaas/Classes/Core/Services/Repository/UserActivities/UserActivityService.swift @@ -173,7 +173,7 @@ public class UserActivityService { // construct url urlString = baseURL + URLHelper.shared.getUserLoginInfoURL() - Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in + Alamofire.request(urlString, method: .post, parameters: bodyParams, encoding: JSONEncoding.default, headers: headers).validate().responseString { response in switch response.result { case .failure(let error): if error._domain == NSURLErrorDomain {