Skip to content

Commit 51c80cf

Browse files
Merge pull request #50 from Cidaas/development
Development
2 parents fc2fd87 + d655aa0 commit 51c80cf

File tree

13 files changed

+145
-83
lines changed

13 files changed

+145
-83
lines changed

Cidaas.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'Cidaas'
11-
s.version = '1.1.0.1'
11+
s.version = '1.1.0.2'
1212
s.summary = 'Native SDK for iOS providing login, registration and verification functionalities'
1313
s.homepage = 'https://github.com/Cidaas/cidaas-sdk-ios-v2'
1414
s.license = { :type => 'MIT', :file => 'LICENSE' }
@@ -19,5 +19,6 @@ Pod::Spec.new do |s|
1919
s.dependency 'Alamofire', '~> 4.7.3'
2020
s.dependency 'OneTimePassword', '~> 3.1.4'
2121
s.dependency 'CryptoSwift', '~> 0.12'
22+
s.dependency 'SwiftKeychainWrapper', '~> 3.0'
2223

2324
end

Cidaas/Classes/Core/Controllers/Repository/AccessToken/AccessTokenController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class AccessTokenController {
7070

7171
// getting current seconds
7272
let milliseconds = Date().timeIntervalSince1970
73-
let seconds = Int64(milliseconds / 1000)
73+
let seconds = Int64(milliseconds)
7474

7575
let accessTokenModel = DBHelper.shared.getAccessToken(key: sub)
7676
let expires = accessTokenModel.expires_in
@@ -222,7 +222,7 @@ public class AccessTokenController {
222222

223223
// set current time
224224
let milliseconds = Date().timeIntervalSince1970
225-
let seconds = Int64(milliseconds / 1000)
225+
let seconds = Int64(milliseconds)
226226
accessTokenModel.seconds = seconds
227227

228228
// save access token in local db

Cidaas/Classes/Core/Controllers/Repository/Login/LoginController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class LoginController {
4040
let loginURL = constructURL(extraParams: extraParams, properties: properties)
4141
let redirectURL = URL(string: properties["RedirectURL"] ?? "")!
4242

43-
if #available(iOS 11.0, *) {
43+
if #available(iOS 12.0, *) {
4444

4545
// initiate safari session with the constructed url performing single sign on
4646
let session = SafariAuthenticationSession(loginURL: loginURL, redirectURL: redirectURL, callback: callback)
@@ -74,7 +74,7 @@ public class LoginController {
7474
let loginURL = constructSocialURL(provider: provider, requestId: requestId, properties: properties)
7575
let redirectURL = URL(string: properties["RedirectURL"] ?? "")!
7676

77-
if #available(iOS 11.0, *) {
77+
if #available(iOS 12.0, *) {
7878

7979
// initiate safari session with the constructed url performing single sign on
8080
let session = SafariAuthenticationSession(loginURL: loginURL, redirectURL: redirectURL, callback: callback)
@@ -94,7 +94,7 @@ public class LoginController {
9494

9595
// assign url to safari controller
9696
let vc = SFSafariViewController(url: loginURL)
97-
97+
vc.view.tintColor = UIColor.orange
9898
// present the safari controller
9999
self.delegate.present(vc, animated: true, completion: nil)
100100
}

Cidaas/Classes/Core/Helpers/Session/SafariAuthenticationSession.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
import Foundation
99
import SafariServices
10+
import AuthenticationServices
1011

11-
@available(iOS 11.0, *)
12+
@available(iOS 12.0, *)
1213
public class SafariAuthenticationSession : AuthSession {
1314

14-
var authSession: SFAuthenticationSession?
15+
var authSession: ASWebAuthenticationSession?
1516
var loginURL: URL
1617

1718
public init(loginURL : URL, redirectURL : URL, callback: @escaping (Result<LoginResponseEntity>) -> ()) {
1819
self.loginURL = loginURL
1920
super.init(redirectURL: redirectURL, callback: callback)
20-
self.authSession = SFAuthenticationSession(url: self.loginURL, callbackURLScheme: self.redirectURL.absoluteString, completionHandler: { (resultURL, resultError) in
21+
self.authSession = ASWebAuthenticationSession(url: self.loginURL, callbackURLScheme: self.redirectURL.absoluteString, completionHandler: { (resultURL, resultError) in
2122
guard resultError == nil, let callbackURL = resultURL else {
2223
if case SFAuthenticationError.canceledLogin = resultError! {
2324
callback(Result.failure(error: WebAuthError.shared.userCancelledException()))

Cidaas/Classes/Core/Services/Repository/Verification/Face/FaceVerificationService.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ public class FaceVerificationService {
281281
}
282282

283283
let uploadImage = UIImageJPEGRepresentation(photo, 0.01)
284-
285-
multipartFormData.append(uploadImage!, withName: "photo", fileName: "photo.jpg", mimeType: "image/jpeg")
284+
if enrollFaceEntity.usage_pass != "" {
285+
multipartFormData.append(uploadImage!, withName: "photo", fileName: "photo.jpg", mimeType: "image/jpeg")
286+
}
286287
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")
287288

288289
}, with: enrolledURL,
@@ -498,7 +499,9 @@ public class FaceVerificationService {
498499

499500
let uploadImage = UIImageJPEGRepresentation(photo, 0.01)
500501

501-
multipartFormData.append(uploadImage!, withName: "photo", fileName: "photo.jpg", mimeType: "image/jpeg")
502+
if authenticateFaceEntity.usage_pass != "" {
503+
multipartFormData.append(uploadImage!, withName: "photo", fileName: "photo.jpg", mimeType: "image/jpeg")
504+
}
502505
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")
503506

504507
}, with: enrolledURL,

Cidaas/Classes/Core/Services/Repository/Verification/Voice/VoiceVerificationService.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ public class VoiceVerificationService {
280280
for (key, value) in bodyParams {
281281
multipartFormData.append(value.data(using: .utf8)!, withName: key)
282282
}
283-
284-
multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
283+
if enrollVoiceEntity.usage_pass != "" {
284+
multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
285+
}
285286
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")
286287

287288
}, with: enrolledURL,
@@ -494,8 +495,9 @@ public class VoiceVerificationService {
494495
for (key, value) in bodyParams {
495496
multipartFormData.append(value.data(using: .utf8)!, withName: key)
496497
}
497-
498-
multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
498+
if authenticateVoiceEntity.usage_pass != "" {
499+
multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
500+
}
499501
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")
500502

501503
}, with: enrolledURL,

Cidaas/Classes/Core/Views/Cidaas.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import SafariServices
11+
import SwiftKeychainWrapper
1112

1213
public class Cidaas {
1314

@@ -60,10 +61,27 @@ public class Cidaas {
6061
// -------------------------------------------------------------------------------------------------- //
6162

6263
// constructor
63-
init(storage : TransactionStore = TransactionStore.shared) {
64+
public init(storage : TransactionStore = TransactionStore.shared) {
6465
// set device info in local
6566
deviceInfo = DeviceInfoModel()
66-
deviceInfo.deviceId = UIDevice.current.identifierForVendor?.uuidString ?? ""
67+
68+
// check device id in keychain
69+
if let sdk_device_id = KeychainWrapper.standard.string(forKey: "cidaas_sdk_device_id") {
70+
// log device id
71+
let loggerMessage = "Device Id in Keychain : " + sdk_device_id
72+
logw(loggerMessage, cname: "cidaas-sdk-info-log")
73+
74+
deviceInfo.deviceId = sdk_device_id
75+
}
76+
else {
77+
// save device id
78+
let sdk_device_id = UIDevice.current.identifierForVendor?.uuidString ?? ""
79+
_ = KeychainWrapper.standard.set(sdk_device_id, forKey: "cidaas_sdk_device_id")
80+
let loggerMessage = "Device Id after saving in Keychain : " + sdk_device_id
81+
logw(loggerMessage, cname: "cidaas-sdk-info-log")
82+
83+
deviceInfo.deviceId = sdk_device_id
84+
}
6785
deviceInfo.deviceMake = "Apple"
6886
let deviceHelper = DeviceHelper()
6987
deviceInfo.deviceModel = String(describing: deviceHelper.hardware())
@@ -2302,6 +2320,14 @@ public class Cidaas {
23022320
// 1. Call setAccessToken method
23032321

23042322
public func setAccessToken(accessTokenEntity: AccessTokenEntity, callback: @escaping(Result<LoginResponseEntity>) -> Void) {
2323+
2324+
// validate fields
2325+
if accessTokenEntity.access_token == "" || accessTokenEntity.expires_in == 0 || accessTokenEntity.refresh_token == "" || accessTokenEntity.sub == "" {
2326+
let error = WebAuthError.shared.propertyMissingException()
2327+
error.errorMessage = "access_token or expires_in or refresh_token or sub must not be empty"
2328+
callback(Result.failure(error: error))
2329+
}
2330+
23052331
// assign to access token model
23062332
EntityToModelConverter.shared.accessTokenEntityToAccessTokenModel(accessTokenEntity: accessTokenEntity, callback: { _ in
23072333

Example/Cidaas.xcodeproj/project.pbxproj

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@
437437
"${BUILT_PRODUCTS_DIR}/Cidaas/Cidaas.framework",
438438
"${BUILT_PRODUCTS_DIR}/CryptoSwift/CryptoSwift.framework",
439439
"${BUILT_PRODUCTS_DIR}/OneTimePassword/OneTimePassword.framework",
440+
"${BUILT_PRODUCTS_DIR}/SwiftKeychainWrapper/SwiftKeychainWrapper.framework",
440441
);
441442
name = "[CP] Embed Pods Frameworks";
442443
outputPaths = (
@@ -445,6 +446,7 @@
445446
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cidaas.framework",
446447
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CryptoSwift.framework",
447448
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OneTimePassword.framework",
449+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftKeychainWrapper.framework",
448450
);
449451
runOnlyForDeploymentPostprocessing = 0;
450452
shellPath = /bin/sh;
@@ -676,10 +678,7 @@
676678
GCC_PRECOMPILE_PREFIX_HEADER = NO;
677679
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
678680
INFOPLIST_FILE = Cidaas/Info.plist;
679-
LD_RUNPATH_SEARCH_PATHS = (
680-
"$(inherited)",
681-
"@executable_path/Frameworks",
682-
);
681+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
683682
MODULE_NAME = ExampleApp;
684683
PRODUCT_BUNDLE_IDENTIFIER = com.cidaas.sdk.demo;
685684
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -700,10 +699,7 @@
700699
GCC_PRECOMPILE_PREFIX_HEADER = NO;
701700
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
702701
INFOPLIST_FILE = Cidaas/Info.plist;
703-
LD_RUNPATH_SEARCH_PATHS = (
704-
"$(inherited)",
705-
"@executable_path/Frameworks",
706-
);
702+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
707703
MODULE_NAME = ExampleApp;
708704
PRODUCT_BUNDLE_IDENTIFIER = com.cidaas.sdk.demo;
709705
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -726,11 +722,7 @@
726722
"$(inherited)",
727723
);
728724
INFOPLIST_FILE = Tests/Info.plist;
729-
LD_RUNPATH_SEARCH_PATHS = (
730-
"$(inherited)",
731-
"@executable_path/Frameworks",
732-
"@loader_path/Frameworks",
733-
);
725+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
734726
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
735727
PRODUCT_NAME = "$(TARGET_NAME)";
736728
SWIFT_VERSION = 4.0;
@@ -748,11 +740,7 @@
748740
"$(inherited)",
749741
);
750742
INFOPLIST_FILE = Tests/Info.plist;
751-
LD_RUNPATH_SEARCH_PATHS = (
752-
"$(inherited)",
753-
"@executable_path/Frameworks",
754-
"@loader_path/Frameworks",
755-
);
743+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
756744
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
757745
PRODUCT_NAME = "$(TARGET_NAME)";
758746
SWIFT_VERSION = 4.0;

Example/Cidaas/Main.storyboard

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,7 @@
1717
<view key="view" contentMode="scaleToFill" id="qhB-a3-VD1">
1818
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
1919
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20-
<subviews>
21-
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1wJ-my-kAA">
22-
<rect key="frame" x="105" y="391" width="154" height="48"/>
23-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
24-
<color key="backgroundColor" red="1" green="0.57637232540000005" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
25-
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
26-
<state key="normal" title="LOGIN">
27-
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
28-
</state>
29-
<connections>
30-
<action selector="loginAction:" destination="eVY-Ca-2R4" eventType="touchUpInside" id="4pu-0q-tIA"/>
31-
</connections>
32-
</button>
33-
</subviews>
34-
<color key="backgroundColor" red="0.964366614818573" green="0.97249454259872437" blue="0.98068743944168091" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
<color key="backgroundColor" red="0.92146831750869751" green="0.92162626981735229" blue="0.92145836353302002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3521
<viewLayoutGuide key="safeArea" id="F1r-ws-735"/>
3622
</view>
3723
<navigationItem key="navigationItem" title="cidaas" id="GLN-eY-Cdw"/>

Example/Cidaas/ViewController.swift

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,74 @@ import UIKit
1010
import Cidaas
1111

1212
class ViewController: UIViewController {
13-
14-
var requestId: String = ""
13+
14+
var cidaas = Cidaas.shared
1515

1616
// did load
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
19+
self.getRequestId()
1920
}
2021

2122
// did receive memory warning
2223
override func didReceiveMemoryWarning() {
2324
super.didReceiveMemoryWarning()
2425
}
25-
26-
@IBAction func loginAction(_ sender: Any) {
27-
28-
Cidaas.shared.loginWithSocial(provider: "linkedin", delegate: self) {
26+
27+
// login with browser
28+
func loginWithBrowser() {
29+
self.cidaas.loginWithBrowser(delegate: self) {
2930
switch $0 {
3031
case .success(let loginSuccessResponse):
3132
print(loginSuccessResponse.data.access_token)
3233
break
33-
case .failure(let loginErrorResponse):
34-
print(loginErrorResponse.errorMessage)
34+
case .failure(let loginFailureResponse):
35+
print(loginFailureResponse.errorMessage)
36+
break
37+
}
38+
}
39+
}
40+
41+
// get request id
42+
func getRequestId() {
43+
self.cidaas.getRequestId() {
44+
switch $0 {
45+
case .success(let requestIdSuccessResponse):
46+
print(requestIdSuccessResponse.data.requestId)
47+
self.loginWithBrowser()
48+
break
49+
case .failure(let requestIdFailureResponse):
50+
print(requestIdFailureResponse.errorMessage)
51+
break
52+
}
53+
}
54+
}
55+
56+
// get tenant information
57+
func getTenantInformation() {
58+
self.cidaas.getTenantInfo() {
59+
switch $0 {
60+
case .success(let tenantInfoSuccessResponse):
61+
print(tenantInfoSuccessResponse.data.tenant_name)
62+
break
63+
case .failure(let tenantInfoFailureResponse):
64+
print(tenantInfoFailureResponse.errorMessage)
65+
break
66+
}
67+
}
68+
}
69+
70+
// get client information
71+
func getClientInformation() {
72+
self.cidaas.getClientInfo() {
73+
switch $0 {
74+
case .success(let clientInfoSuccessResponse):
75+
print(clientInfoSuccessResponse.data.login_providers)
76+
break
77+
case .failure(let clientInfoFailureResponse):
78+
print(clientInfoFailureResponse.errorMessage)
3579
break
3680
}
3781
}
38-
39-
// Cidaas.shared.loginWithBrowser(delegate: self) {
40-
// switch $0 {
41-
// case .failure(let errorResponse):
42-
// print(errorResponse.errorMessage)
43-
// break
44-
// case .success(let successResponse):
45-
// let alert = UIAlertController(title: "Access Token", message: "\(successResponse.data.access_token)", preferredStyle: .alert)
46-
// alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
47-
// self.present(alert, animated: true, completion: nil)
48-
// break
49-
// }
50-
// }
51-
52-
// guard let url = URL(string: "https://stackoverflow.com") else { return }
53-
// UIApplication.shared.open(url)
54-
5582
}
5683
}

0 commit comments

Comments
 (0)