Skip to content

Commit

Permalink
Merge pull request #36 from Cidaas/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cidaas-samples authored Nov 23, 2018
2 parents 2c68eb1 + 970c1e5 commit c363a87
Show file tree
Hide file tree
Showing 17 changed files with 502 additions and 300 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.4'
s.version = '1.0.5'
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class PatternVerificationController {
return
case .success(let serviceResponse):
// log success
let loggerMessage = "Configure Pattern service success : " + "Status Id - " + String(describing: serviceResponse.data.st)
let loggerMessage = "Configure Pattern service success : " + "Current Status - " + String(describing: serviceResponse.data.current_status)
logw(loggerMessage, cname: "cidaas-sdk-success-log")

var timer: Timer = Timer()
Expand Down Expand Up @@ -308,6 +308,10 @@ public class PatternVerificationController {
return
}

if enrollPatternEntity.userDeviceId == "" {
enrollPatternEntity.userDeviceId = DBHelper.shared.getUserDeviceId(key: properties["DomainURL"] ?? "OAuthUserDeviceId")
}

// validating fields
if (enrollPatternEntity.statusId == "" || enrollPatternEntity.userDeviceId == "" || enrollPatternEntity.verifierPassword == "") {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -341,8 +345,6 @@ public class PatternVerificationController {
let loggerMessage = "Enroll Pattern success : " + "Tracking Code - " + String(describing: enrollResponse.data.trackingCode + ", Sub - " + String(describing: enrollResponse.data.sub))
logw(loggerMessage, cname: "cidaas-sdk-success-log")

// default set intermediate id to empty
Cidaas.intermediate_verifiation_id = intermediate_id

var timer: Timer = Timer()
var timerCount: Int16 = 0
Expand Down Expand Up @@ -709,7 +711,7 @@ public class PatternVerificationController {

// return success callback
DispatchQueue.main.async {
callback(Result.success(result: patternResponse))
callback(Result.success(result: initiatePatternResponse))
}

break
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class AuthenticatePatternEntity : Codable {
public var verifierPassword: String = ""
public var userDeviceId: String = ""
public var usage_pass: 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 @@ -13,6 +13,7 @@ public class EnrollPatternEntity : Codable {
public var verifierPassword: String = ""
public var userDeviceId: String = ""
public var usage_pass: 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 @@ -12,6 +12,8 @@ public class AuthenticatePushEntity : Codable {
public var statusId: String = ""
public var verifierPassword: String = ""
public var userDeviceId: String = ""
public var usage_pass: 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 AuthenticatePushResponseDataEntity : 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 AuthenticatePushResponseDataEntity : 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,8 @@ public class EnrollPushEntity : Codable {
public var statusId: String = ""
public var verifierPassword: String = ""
public var userDeviceId: String = ""
public var usage_pass: 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 @@ -28,6 +28,7 @@ public class EnrollPushResponseEntity : Codable {

public class EnrollPushResponseDataEntity : 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 EnrollPushResponseDataEntity : 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 @@ -17,7 +17,6 @@ public class InitiatePushEntity : 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 @@ -11,6 +11,7 @@ public class ScannedPushEntity : 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 @@ -29,6 +29,7 @@ public class ScannedPushResponseEntity : Codable {
public class ScannedPushResponseDataEntity : Codable {
// properties
public var userDeviceId: String = ""
public var current_status: String = ""

// Constructors
public init() {
Expand All @@ -38,5 +39,6 @@ public class ScannedPushResponseDataEntity : 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 @@ -9,8 +9,9 @@ import Foundation

public class SetupPushEntity : Codable {
// properties
public var logoUrl: String = ""
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 SetupPushResponseEntity : Codable {

public class SetupPushResponseDataEntity : 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 SetupPushResponseDataEntity : 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
Expand Up @@ -35,6 +35,7 @@ public class PatternVerificationService {
// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version": "2",
"access_token" : accessToken
]
deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
Expand Down Expand Up @@ -135,12 +136,13 @@ public class PatternVerificationService {

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

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

scannedPatternEntity.client_id = properties["ClientId"] ?? ""

// construct body params
var bodyParams = Dictionary<String, Any>()
Expand Down Expand Up @@ -237,12 +239,13 @@ public class PatternVerificationService {
// construct headers
headers = [
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version": "2",
"access_token" : accessToken
]

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

enrollPatternEntity.client_id = properties["ClientId"] ?? ""

// construct body params
var bodyParams = Dictionary<String, Any>()
Expand Down Expand Up @@ -338,7 +341,8 @@ public class PatternVerificationService {

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

deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
Expand Down Expand Up @@ -436,108 +440,13 @@ public class PatternVerificationService {

// construct headers
headers = [
"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()
"User-Agent": CidaasUserAgentBuilder.shared.UAString(),
"verification_api_version": "2"
]

deviceInfoEntity.pushNotificationId = DBHelper.shared.getFCM()
authenticatePatternEntity.deviceInfo = deviceInfoEntity
authenticatePatternEntity.client_id = properties["ClientId"] ?? ""

// construct body params
var bodyParams = Dictionary<String, Any>()
Expand Down
Loading

0 comments on commit c363a87

Please sign in to comment.