Skip to content

Commit

Permalink
Merge pull request #35 from Cidaas/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cidaas-samples authored Nov 21, 2018
2 parents bd46df7 + d69b4dc commit 2c68eb1
Show file tree
Hide file tree
Showing 20 changed files with 694 additions and 191 deletions.
2 changes: 1 addition & 1 deletion Cidaas.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Cidaas'
s.version = '1.0.3'
s.version = '1.0.4'
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' }
Expand Down

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cidaas/Classes/Core/Helpers/Enums/VerificationTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ public enum VerificationTypes : String {
case FACE = "FACE"
case VOICE = "VOICE"
case TOTP = "TOTP"
case EMAIL = "EMAIL"
case SMS = "SMS"
case IVR = "IVR"
case BACKUPCODE = "BACKUPCODE"
}
3 changes: 3 additions & 0 deletions Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,7 @@ public enum WebAuthErrorCode : Int32 {
case DOCUMENT_ENROLLED_SERVICE_FAILURE = 10170

case SOCIAL_TOKEN_SERVICE_FAILURE = 10171

case EMPTY_DELETE_VERIFICATION_SERVICE = 10172
case DELETE_VERIFICATION_SERVICE_FAILURE = 10173
}
4 changes: 2 additions & 2 deletions Cidaas/Classes/Core/Helpers/General/DBHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class DBHelper : NSObject {
let userId = userInfoModel.userId
let data = try encoder.encode(userInfoModel)
let user_info_string = String(data : data, encoding : .utf8)
userDefaults.set(user_info_string, forKey: "cidaas_user_details_\(userId)")
userDefaults.set(user_info_string, forKey: "cidaas_user_info_details_\(userId)")
userDefaults.synchronize()
}
catch {
Expand Down Expand Up @@ -145,7 +145,7 @@ public class DBHelper : NSObject {
// get user info
public func getUserInfo(key : String) -> UserInfoModel? {
let userId = key
guard let value = userDefaults.object(forKey: "cidaas_user_details_\(userId)") else {
guard let value = userDefaults.object(forKey: "cidaas_user_info_details_\(userId)") else {
return nil
}
let user_info_string = value as? String ?? ""
Expand Down
6 changes: 6 additions & 0 deletions Cidaas/Classes/Core/Helpers/General/URLHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class URLHelper {
public var setupTOTPURL = "/verification-srv/totp/setup"
public var enrollTOTPURL = "/verification-srv/totp/enroll"

public var deleteURL = "/verification-srv/settings/delete/"

public var authenticateBackupcodeURL = "/verification-srv/backupcode/authenticate"
public var authenticateTOTPURL = "/verification-srv/totp/authenticate"
public var mfaContinueURL = "/login-srv/precheck/continue/sdk"
Expand Down Expand Up @@ -239,6 +241,10 @@ public class URLHelper {
return authenticateBackupcodeURL
}

public func getDeleteURL(userDeviceId: String, verificationType: String) -> String {
return deleteURL + userDeviceId + "/" + verificationType.uppercased()
}

public func getAuthenticateTOTPURL() -> String {
return authenticateTOTPURL
}
Expand Down
3 changes: 3 additions & 0 deletions Cidaas/Classes/Core/Helpers/Locale/StringsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,7 @@ public class StringsHelper {
public var DOCUMENT_ENROLLED_SERVICE_FAILURE: String = "Document Scan service failure"

public var SOCIAL_TOKEN_SERVICE_FAILURE: String = "Social token service failure"

public var EMPTY_DELETE_VERIFICATION_SERVICE: String = "Delete verification service is empty"
public var DELETE_VERIFICATION_SERVICE_FAILURE: String = "Delete verification service failure"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AuthenticatePatternEntity : Codable {
public var statusId: String = ""
public var verifierPassword: String = ""
public var userDeviceId: String = ""
public var usage_pass: String = ""
public var deviceInfo: DeviceInfoModel = DeviceInfoModel()

// Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class AuthenticatePatternResponseDataEntity : Codable {
// properties
public var sub: String = ""
public var trackingCode: String = ""
public var current_status: String = ""

// Constructors
public init() {
Expand All @@ -40,5 +41,6 @@ public class AuthenticatePatternResponseDataEntity : Codable {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.sub = try container.decodeIfPresent(String.self, forKey: .sub) ?? ""
self.trackingCode = try container.decodeIfPresent(String.self, forKey: .trackingCode) ?? ""
self.current_status = try container.decodeIfPresent(String.self, forKey: .current_status) ?? ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class EnrollPatternEntity : Codable {
public var statusId: String = ""
public var verifierPassword: String = ""
public var userDeviceId: String = ""
public var usage_pass: String = ""
public var deviceInfo: DeviceInfoModel = DeviceInfoModel()

// Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EnrollPatternResponseEntity : Codable {

public class EnrollPatternResponseDataEntity : Codable {
// properties
public var current_status: String = ""
public var sub: String = ""
public var trackingCode: String = ""
public var verificationType: String = ""
Expand All @@ -40,6 +41,7 @@ public class EnrollPatternResponseDataEntity : Codable {

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.current_status = try container.decodeIfPresent(String.self, forKey: .current_status) ?? ""
self.sub = try container.decodeIfPresent(String.self, forKey: .sub) ?? ""
self.trackingCode = try container.decodeIfPresent(String.self, forKey: .trackingCode) ?? ""
self.verificationType = try container.decodeIfPresent(String.self, forKey: .verificationType) ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class InitiatePatternEntity : Codable {
public var client_id: String = ""
public var usage_pass: String = ""
public var deviceInfo: DeviceInfoModel = DeviceInfoModel()
public var source: String = "MOBILE"

// Constructors
public init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ScannedPatternEntity : Codable {
// properties
public var usage_pass: String = ""
public var statusId: String = ""
public var client_id: String = ""
public var deviceInfo: DeviceInfoModel = DeviceInfoModel()

// Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ScannedPatternResponseEntity : Codable {
public class ScannedPatternResponseDataEntity : Codable {
// properties
public var userDeviceId: String = ""
public var current_status: String = ""

// Constructors
public init() {
Expand All @@ -39,5 +40,6 @@ public class ScannedPatternResponseDataEntity : Codable {
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.userDeviceId = try container.decodeIfPresent(String.self, forKey: .userDeviceId) ?? ""
self.current_status = try container.decodeIfPresent(String.self, forKey: .current_status) ?? ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SetupPatternEntity : Codable {
// properties
public var client_id: String = ""
public var logoUrl: String = ""
public var usage_pass: String = ""
public var deviceInfo: DeviceInfoModel = DeviceInfoModel()

// Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ public class SetupPatternResponseEntity : Codable {

public class SetupPatternResponseDataEntity : Codable {
// properties
public var qrCode: String = ""
public var queryString: String = ""
public var statusId: String = ""
public var verifierId: String = ""
public var randomNumber: String = ""
public var secret: String = ""
public var t: String = ""
public var d: String = ""
public var issuer: String = ""
public var l: String = ""
public var sub: String = ""
public var rns: String = ""
public var cid: String = ""
public var rurl: String = ""
public var st: String = ""
public var udi: String = ""
public var current_status: String = ""

// Constructors
Expand All @@ -43,11 +49,17 @@ public class SetupPatternResponseDataEntity : Codable {

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.qrCode = try container.decodeIfPresent(String.self, forKey: .qrCode) ?? ""
self.queryString = try container.decodeIfPresent(String.self, forKey: .queryString) ?? ""
self.statusId = try container.decodeIfPresent(String.self, forKey: .statusId) ?? ""
self.verifierId = try container.decodeIfPresent(String.self, forKey: .verifierId) ?? ""
self.randomNumber = try container.decodeIfPresent(String.self, forKey: .randomNumber) ?? ""
self.secret = try container.decodeIfPresent(String.self, forKey: .secret) ?? ""
self.t = try container.decodeIfPresent(String.self, forKey: .t) ?? ""
self.d = try container.decodeIfPresent(String.self, forKey: .d) ?? ""
self.issuer = try container.decodeIfPresent(String.self, forKey: .issuer) ?? ""
self.l = try container.decodeIfPresent(String.self, forKey: .l) ?? ""
self.sub = try container.decodeIfPresent(String.self, forKey: .sub) ?? ""
self.rns = try container.decodeIfPresent(String.self, forKey: .rns) ?? ""
self.cid = try container.decodeIfPresent(String.self, forKey: .cid) ?? ""
self.rurl = try container.decodeIfPresent(String.self, forKey: .rurl) ?? ""
self.st = try container.decodeIfPresent(String.self, forKey: .st) ?? ""
self.udi = try container.decodeIfPresent(String.self, forKey: .udi) ?? ""
self.current_status = try container.decodeIfPresent(String.self, forKey: .current_status) ?? ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// DeleteResponseEntity.swift
// Cidaas
//
// Created by ganesh on 21/11/18.
//

import Foundation

public class DeleteResponseEntity : Codable {
// properties
public var success: Bool = false
public var status: Int16 = 0

// 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) ?? 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public class PatternVerificationService {
// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version" : "2",
"access_token" : accessToken,
"access_challenge" : properties["Challenge"] ?? "",
"access_challenge_method" : properties["Method"] ?? ""
"access_token" : accessToken
]
deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
setupPatternEntity.deviceInfo = deviceInfoEntity
Expand Down Expand Up @@ -124,7 +121,7 @@ public class PatternVerificationService {
}

// scanned pattern
public func scannedPattern(accessToken: String, scannedPatternEntity: ScannedPatternEntity, properties : Dictionary<String, String>, callback: @escaping(Result<ScannedPatternResponseEntity>) -> Void) {
public func scannedPattern(scannedPatternEntity: ScannedPatternEntity, properties : Dictionary<String, String>, callback: @escaping(Result<ScannedPatternResponseEntity>) -> Void) {
// local variables
var headers : HTTPHeaders
var urlString : String
Expand All @@ -138,9 +135,7 @@ public class PatternVerificationService {

// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version" : "2",
"access_token" : accessToken
"User-Agent": CidaasUserAgentBuilder.shared.UAString()
]

deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
Expand Down Expand Up @@ -242,7 +237,6 @@ public class PatternVerificationService {
// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version" : "2",
"access_token" : accessToken
]

Expand Down Expand Up @@ -344,10 +338,7 @@ public class PatternVerificationService {

// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version" : "2",
"access_challenge" : properties["Challenge"] ?? "",
"access_challenge_method" : properties["Method"] ?? ""
"User-Agent": CidaasUserAgentBuilder.shared.UAString()
]

deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
Expand Down Expand Up @@ -445,8 +436,104 @@ public class PatternVerificationService {

// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version": "2"
"User-Agent": CidaasUserAgentBuilder.shared.UAString()
]

deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
authenticatePatternEntity.deviceInfo = deviceInfoEntity

// construct body params
var bodyParams = Dictionary<String, Any>()
do {
let encoder = JSONEncoder()
let data = try encoder.encode(authenticatePatternEntity)
bodyParams = try! JSONSerialization.jsonObject(with: data, options: []) as? Dictionary<String, Any> ?? Dictionary<String, Any>()
}
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.getAuthenticatePatternURL()

// call service
Alamofire.request(urlString, method: .post, parameters: bodyParams, headers: headers).validate().responseString { response in
switch response.result {
case .success:
if response.response?.statusCode == 200 {
if let jsonString = response.result.value {
let decoder = JSONDecoder()
do {
let data = jsonString.data(using: .utf8)!
// decode the json data to object
let authenticatePatternResponseEntity = try decoder.decode(AuthenticatePatternResponseEntity.self, from: data)

// return success
callback(Result.success(result: authenticatePatternResponseEntity))
}
catch(let error) {
// return failure
callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.EMPTY_PATTERN_AUTHENTICATE_SERVICE.rawValue, errorMessage: error.localizedDescription, statusCode: 400)))
}
}
else {
// return failure
callback(Result.failure(error: WebAuthError.shared.serviceFailureException(errorCode: WebAuthErrorCode.EMPTY_PATTERN_AUTHENTICATE_SERVICE.rawValue, errorMessage: StringsHelper.shared.EMPTY_PATTERN_AUTHENTICATE_SERVICE, statusCode: response.response?.statusCode ?? 400)))
}
}
else {
// return failure
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:
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.PATTERN_AUTHENTICATE_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.PATTERN_AUTHENTICATE_SERVICE_FAILURE.rawValue, errorMessage: error.localizedDescription, statusCode: 400)))
}
}
else {
// return failure
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, error: ErrorResponseEntity())))
}
break
}
}
}

// Delete pattern
public func deletePattern(authenticatePatternEntity: AuthenticatePatternEntity, properties : Dictionary<String, String>, callback: @escaping(Result<AuthenticatePatternResponseEntity>) -> 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()
]

deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
Expand Down
Loading

0 comments on commit 2c68eb1

Please sign in to comment.