Skip to content

Commit

Permalink
Merge pull request #40 from Cidaas/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cidaas-samples authored Nov 28, 2018
2 parents 160ffd5 + 930b38f commit a61d51f
Show file tree
Hide file tree
Showing 14 changed files with 547 additions and 25 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.8'
s.version = '1.0.9'
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
@@ -0,0 +1,61 @@
//
// SettingsController.swift
// Cidaas
//
// Created by ganesh on 27/11/18.
//

import Foundation

public class SettingsController {

// shared instance
public static var shared : SettingsController = SettingsController()

// constructor
public init() {

}

// get end points
public func getEndpoints(properties: Dictionary<String, String>, callback: @escaping (Result<EndpointsResponseEntity>) -> 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
}

// call getEndpoints service
SettingsService.shared.getEndpoints(properties: properties) {
switch $0 {
case .failure(let error):
// log error
let loggerMessage = "Get endpoints 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 serviceResponse):
// log success
let loggerMessage = "Get endpoints service success : " + "Authz URL - " + serviceResponse.authorization_endpoint
logw(loggerMessage, cname: "cidaas-sdk-success-log")

// return callback
DispatchQueue.main.async {
callback(Result.success(result: serviceResponse))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public class FaceVerificationController {

// Web to Mobile
// enroll Face from properties
public func enrollFaceRecognition(access_token: String, photo: UIImage, enrollFaceEntity: EnrollFaceEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollFaceResponseEntity>) -> Void) {
public func enrollFaceRecognition(sub: String = "", access_token: String, photo: UIImage, enrollFaceEntity: EnrollFaceEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollFaceResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -309,11 +309,42 @@ public class FaceVerificationController {
return
}

if access_token == "" {
if sub == "" {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "access_token or sub must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}
}

// default set intermediate id to empty
Cidaas.intermediate_verifiation_id = intermediate_id
self.verificationType = VerificationTypes.FACE.rawValue
self.authenticationType = AuthenticationTypes.CONFIGURE.rawValue

if access_token == "" {
Cidaas.shared.getAccessToken(sub: sub) {
switch $0 {
case .success(let successResponse):
self.enrollFaceAPI(access_token: successResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback)
break
case .failure(let error):
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
break
}
}
}
else {
self.enrollFaceAPI(access_token: access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback)
}
}

private func enrollFaceAPI(access_token: String, photo: UIImage, enrollFaceEntity: EnrollFaceEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollFaceResponseEntity>) -> Void) {
// call enroll service
FaceVerificationService.shared.enrollFace(accessToken:access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties) {
switch $0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public class PatternVerificationController {

// Web to Mobile
// enroll PatternRecognition from properties
public func enrollPatternRecognition(access_token: String, enrollPatternEntity: EnrollPatternEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollPatternResponseEntity>) -> Void) {
public func enrollPatternRecognition(sub: String = "", access_token: String = "", enrollPatternEntity: EnrollPatternEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollPatternResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -322,11 +322,42 @@ public class PatternVerificationController {
return
}

if access_token == "" {
if sub == "" {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "access_token or sub must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}
}

// default set intermediate id to empty
Cidaas.intermediate_verifiation_id = intermediate_id
self.verificationType = VerificationTypes.PATTERN.rawValue
self.authenticationType = AuthenticationTypes.CONFIGURE.rawValue

if access_token == "" {
Cidaas.shared.getAccessToken(sub: sub) {
switch $0 {
case .success(let successResponse):
self.enrollPatternAPI(access_token: successResponse.data.access_token, enrollPatternEntity: enrollPatternEntity, properties: properties, callback: callback)
break
case .failure(let error):
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
break
}
}
}
else {
self.enrollPatternAPI(access_token: access_token, enrollPatternEntity: enrollPatternEntity, properties: properties, callback: callback)
}
}

private func enrollPatternAPI(access_token: String, enrollPatternEntity: EnrollPatternEntity, properties: Dictionary<String, String>, callback: @escaping(Result<EnrollPatternResponseEntity>) -> Void) {
// call enroll service
PatternVerificationService.shared.enrollPattern(accessToken:access_token, enrollPatternEntity: enrollPatternEntity, properties: properties) {
switch $0 {
Expand Down Expand Up @@ -404,7 +435,6 @@ public class PatternVerificationController {
}
}


// login with pattern recognition from properties
public func loginWithPatternRecognition(pattern: String, email : String, mobile: String, sub: String, trackId: String, requestId: String, usageType: String, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<LoginResponseEntity>) -> Void) {
// null check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public class PushVerificationController {

// Web to Mobile
// enroll push from properties
public func enrollPush(access_token: String, enrollPushEntity: EnrollPushEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollPushResponseEntity>) -> Void) {
public func enrollPush(sub: String = "", access_token: String, enrollPushEntity: EnrollPushEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollPushResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -313,11 +313,43 @@ public class PushVerificationController {
return
}

if access_token == "" {
if sub == "" {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "access_token or sub must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}
}

// default set intermediate id to empty
Cidaas.intermediate_verifiation_id = intermediate_id
self.verificationType = VerificationTypes.PUSH.rawValue
self.authenticationType = AuthenticationTypes.CONFIGURE.rawValue


if access_token == "" {
Cidaas.shared.getAccessToken(sub: sub) {
switch $0 {
case .success(let successResponse):
self.enrollPushAPI(access_token: successResponse.data.access_token, enrollPushEntity: enrollPushEntity, properties: properties, callback: callback)
break
case .failure(let error):
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
break
}
}
}
else {
self.enrollPushAPI(access_token: access_token, enrollPushEntity: enrollPushEntity, properties: properties, callback: callback)
}
}

private func enrollPushAPI(access_token: String, enrollPushEntity: EnrollPushEntity, properties: Dictionary<String, String>, callback: @escaping(Result<EnrollPushResponseEntity>) -> Void) {
// call enroll service
PushVerificationService.shared.enrollPush(accessToken:access_token, enrollPushEntity: enrollPushEntity, properties: properties) {
switch $0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class TouchIdVerificationController {
enrollTouchEntity.statusId = self.statusId

// call scanned TouchId service
TouchIdVerificationController.shared.enrollToucId(access_token:tokenResponse.data.access_token, enrollTouchEntity: enrollTouchEntity, properties: properties) {
TouchIdVerificationController.shared.enrollTouchId(access_token:tokenResponse.data.access_token, enrollTouchEntity: enrollTouchEntity, properties: properties) {
switch $0 {
case .failure(let error):
// return failure callback
Expand Down Expand Up @@ -283,7 +283,7 @@ public class TouchIdVerificationController {

// Web to Mobile
// enroll Touch Id from properties
public func enrollToucId(access_token: String, enrollTouchEntity: EnrollTouchEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollTouchResponseEntity>) -> Void) {
public func enrollTouchId(sub: String = "", access_token: String, enrollTouchEntity: EnrollTouchEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollTouchResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -311,11 +311,42 @@ public class TouchIdVerificationController {
return
}

if access_token == "" {
if sub == "" {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "access_token or sub must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}
}

// default set intermediate id to empty
Cidaas.intermediate_verifiation_id = intermediate_id
self.verificationType = VerificationTypes.TOUCH.rawValue
self.authenticationType = AuthenticationTypes.CONFIGURE.rawValue

if access_token == "" {
Cidaas.shared.getAccessToken(sub: sub) {
switch $0 {
case .success(let successResponse):
self.enrollTouchAPI(access_token: successResponse.data.access_token, enrollTouchEntity: enrollTouchEntity, properties: properties, callback: callback)
break
case .failure(let error):
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
break
}
}
}
else {
self.enrollTouchAPI(access_token: access_token, enrollTouchEntity: enrollTouchEntity, properties: properties, callback: callback)
}
}

private func enrollTouchAPI(access_token: String, enrollTouchEntity: EnrollTouchEntity, properties: Dictionary<String, String>, callback: @escaping(Result<EnrollTouchResponseEntity>) -> Void) {
// call enroll service
TouchIdVerificationService.shared.enrollTouchId(accessToken:access_token, enrollTouchIdEntity: enrollTouchEntity, properties: properties) {
switch $0 {
Expand Down Expand Up @@ -393,7 +424,6 @@ public class TouchIdVerificationController {
}
}


// login with TouchId from properties
public func loginWithTouchId(email : String, mobile: String, sub: String, trackId: String, requestId: String, usageType: String, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<LoginResponseEntity>) -> Void) {
// null check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public class VoiceVerificationController {

// Web to Mobile
// enroll Voice from properties
public func enrollVoiceRecognition(access_token: String, voice: Data, enrollVoiceEntity: EnrollVoiceEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollVoiceResponseEntity>) -> Void) {
public func enrollVoiceRecognition(sub: String = "", access_token: String, voice: Data, enrollVoiceEntity: EnrollVoiceEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollVoiceResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -308,11 +308,42 @@ public class VoiceVerificationController {
return
}

if access_token == "" {
if sub == "" {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "access_token or sub must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}
}

// default set intermediate id to empty
Cidaas.intermediate_verifiation_id = intermediate_id
self.verificationType = VerificationTypes.VOICE.rawValue
self.authenticationType = AuthenticationTypes.CONFIGURE.rawValue

if access_token == "" {
Cidaas.shared.getAccessToken(sub: sub) {
switch $0 {
case .success(let successResponse):
self.enrollVoiceAPI(access_token: successResponse.data.access_token, voice: voice, enrollVoiceEntity: enrollVoiceEntity, properties: properties, callback: callback)
break
case .failure(let error):
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
break
}
}
}
else {
self.enrollVoiceAPI(access_token: access_token, voice: voice, enrollVoiceEntity: enrollVoiceEntity, properties: properties, callback: callback)
}
}

private func enrollVoiceAPI(access_token: String, voice: Data, enrollVoiceEntity: EnrollVoiceEntity, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollVoiceResponseEntity>) -> Void) {
// call enroll service
VoiceVerificationService.shared.enrollVoice(accessToken:access_token, voice: voice, enrollVoiceEntity: enrollVoiceEntity, properties: properties) {
switch $0 {
Expand Down Expand Up @@ -390,7 +421,6 @@ public class VoiceVerificationController {
}
}


// login with Voice from properties
public func loginWithVoice(email : String, mobile: String, sub: String, trackId: String, requestId: String, voice: Data, usageType: String, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<LoginResponseEntity>) -> Void) {
// null check
Expand Down
2 changes: 2 additions & 0 deletions Cidaas/Classes/Core/Helpers/Enums/WebAuthErrorCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,6 @@ public enum WebAuthErrorCode : Int32 {

case EMPTY_DELETE_VERIFICATION_SERVICE = 10172
case DELETE_VERIFICATION_SERVICE_FAILURE = 10173

case END_POINTS_SERVICE_FAILURE = 10174
}
Loading

0 comments on commit a61d51f

Please sign in to comment.