Skip to content

Commit

Permalink
Merge pull request #51 from Cidaas/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
cidaas-samples authored Dec 17, 2018
2 parents 8217f61 + 51c80cf commit 3db4602
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 83 deletions.
3 changes: 2 additions & 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.1.0.1'
s.version = '1.1.0.2'
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 All @@ -19,5 +19,6 @@ Pod::Spec.new do |s|
s.dependency 'Alamofire', '~> 4.7.3'
s.dependency 'OneTimePassword', '~> 3.1.4'
s.dependency 'CryptoSwift', '~> 0.12'
s.dependency 'SwiftKeychainWrapper', '~> 3.0'

end
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class AccessTokenController {

// getting current seconds
let milliseconds = Date().timeIntervalSince1970
let seconds = Int64(milliseconds / 1000)
let seconds = Int64(milliseconds)

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

// set current time
let milliseconds = Date().timeIntervalSince1970
let seconds = Int64(milliseconds / 1000)
let seconds = Int64(milliseconds)
accessTokenModel.seconds = seconds

// save access token in local db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class LoginController {
let loginURL = constructURL(extraParams: extraParams, properties: properties)
let redirectURL = URL(string: properties["RedirectURL"] ?? "")!

if #available(iOS 11.0, *) {
if #available(iOS 12.0, *) {

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

if #available(iOS 11.0, *) {
if #available(iOS 12.0, *) {

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

// assign url to safari controller
let vc = SFSafariViewController(url: loginURL)

vc.view.tintColor = UIColor.orange
// present the safari controller
self.delegate.present(vc, animated: true, completion: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

import Foundation
import SafariServices
import AuthenticationServices

@available(iOS 11.0, *)
@available(iOS 12.0, *)
public class SafariAuthenticationSession : AuthSession {

var authSession: SFAuthenticationSession?
var authSession: ASWebAuthenticationSession?
var loginURL: URL

public init(loginURL : URL, redirectURL : URL, callback: @escaping (Result<LoginResponseEntity>) -> ()) {
self.loginURL = loginURL
super.init(redirectURL: redirectURL, callback: callback)
self.authSession = SFAuthenticationSession(url: self.loginURL, callbackURLScheme: self.redirectURL.absoluteString, completionHandler: { (resultURL, resultError) in
self.authSession = ASWebAuthenticationSession(url: self.loginURL, callbackURLScheme: self.redirectURL.absoluteString, completionHandler: { (resultURL, resultError) in
guard resultError == nil, let callbackURL = resultURL else {
if case SFAuthenticationError.canceledLogin = resultError! {
callback(Result.failure(error: WebAuthError.shared.userCancelledException()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ public class FaceVerificationService {
}

let uploadImage = UIImageJPEGRepresentation(photo, 0.01)

multipartFormData.append(uploadImage!, withName: "photo", fileName: "photo.jpg", mimeType: "image/jpeg")
if enrollFaceEntity.usage_pass != "" {
multipartFormData.append(uploadImage!, withName: "photo", fileName: "photo.jpg", mimeType: "image/jpeg")
}
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")

}, with: enrolledURL,
Expand Down Expand Up @@ -498,7 +499,9 @@ public class FaceVerificationService {

let uploadImage = UIImageJPEGRepresentation(photo, 0.01)

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

}, with: enrolledURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ public class VoiceVerificationService {
for (key, value) in bodyParams {
multipartFormData.append(value.data(using: .utf8)!, withName: key)
}

multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
if enrollVoiceEntity.usage_pass != "" {
multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
}
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")

}, with: enrolledURL,
Expand Down Expand Up @@ -494,8 +495,9 @@ public class VoiceVerificationService {
for (key, value) in bodyParams {
multipartFormData.append(value.data(using: .utf8)!, withName: key)
}

multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
if authenticateVoiceEntity.usage_pass != "" {
multipartFormData.append(voice, withName: "voice", fileName: "voice.wav", mimeType: "audio/mpeg")
}
enrolledURL.addValue(multipartFormData.contentType, forHTTPHeaderField: "Content-Type")

}, with: enrolledURL,
Expand Down
30 changes: 28 additions & 2 deletions Cidaas/Classes/Core/Views/Cidaas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import SafariServices
import SwiftKeychainWrapper

public class Cidaas {

Expand Down Expand Up @@ -60,10 +61,27 @@ public class Cidaas {
// -------------------------------------------------------------------------------------------------- //

// constructor
init(storage : TransactionStore = TransactionStore.shared) {
public init(storage : TransactionStore = TransactionStore.shared) {
// set device info in local
deviceInfo = DeviceInfoModel()
deviceInfo.deviceId = UIDevice.current.identifierForVendor?.uuidString ?? ""

// check device id in keychain
if let sdk_device_id = KeychainWrapper.standard.string(forKey: "cidaas_sdk_device_id") {
// log device id
let loggerMessage = "Device Id in Keychain : " + sdk_device_id
logw(loggerMessage, cname: "cidaas-sdk-info-log")

deviceInfo.deviceId = sdk_device_id
}
else {
// save device id
let sdk_device_id = UIDevice.current.identifierForVendor?.uuidString ?? ""
_ = KeychainWrapper.standard.set(sdk_device_id, forKey: "cidaas_sdk_device_id")
let loggerMessage = "Device Id after saving in Keychain : " + sdk_device_id
logw(loggerMessage, cname: "cidaas-sdk-info-log")

deviceInfo.deviceId = sdk_device_id
}
deviceInfo.deviceMake = "Apple"
let deviceHelper = DeviceHelper()
deviceInfo.deviceModel = String(describing: deviceHelper.hardware())
Expand Down Expand Up @@ -2302,6 +2320,14 @@ public class Cidaas {
// 1. Call setAccessToken method

public func setAccessToken(accessTokenEntity: AccessTokenEntity, callback: @escaping(Result<LoginResponseEntity>) -> Void) {

// validate fields
if accessTokenEntity.access_token == "" || accessTokenEntity.expires_in == 0 || accessTokenEntity.refresh_token == "" || accessTokenEntity.sub == "" {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "access_token or expires_in or refresh_token or sub must not be empty"
callback(Result.failure(error: error))
}

// assign to access token model
EntityToModelConverter.shared.accessTokenEntityToAccessTokenModel(accessTokenEntity: accessTokenEntity, callback: { _ in

Expand Down
24 changes: 6 additions & 18 deletions Example/Cidaas.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@
"${BUILT_PRODUCTS_DIR}/Cidaas/Cidaas.framework",
"${BUILT_PRODUCTS_DIR}/CryptoSwift/CryptoSwift.framework",
"${BUILT_PRODUCTS_DIR}/OneTimePassword/OneTimePassword.framework",
"${BUILT_PRODUCTS_DIR}/SwiftKeychainWrapper/SwiftKeychainWrapper.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand All @@ -445,6 +446,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cidaas.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CryptoSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OneTimePassword.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftKeychainWrapper.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -676,10 +678,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
INFOPLIST_FILE = Cidaas/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = com.cidaas.sdk.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -700,10 +699,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
INFOPLIST_FILE = Cidaas/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = com.cidaas.sdk.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -726,11 +722,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
Expand All @@ -748,11 +740,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
Expand Down
16 changes: 1 addition & 15 deletions Example/Cidaas/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,7 @@
<view key="view" contentMode="scaleToFill" id="qhB-a3-VD1">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1wJ-my-kAA">
<rect key="frame" x="105" y="391" width="154" height="48"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="0.57637232540000005" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
<state key="normal" title="LOGIN">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="loginAction:" destination="eVY-Ca-2R4" eventType="touchUpInside" id="4pu-0q-tIA"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.964366614818573" green="0.97249454259872437" blue="0.98068743944168091" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.92146831750869751" green="0.92162626981735229" blue="0.92145836353302002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="F1r-ws-735"/>
</view>
<navigationItem key="navigationItem" title="cidaas" id="GLN-eY-Cdw"/>
Expand Down
77 changes: 52 additions & 25 deletions Example/Cidaas/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,74 @@ import UIKit
import Cidaas

class ViewController: UIViewController {

var requestId: String = ""
var cidaas = Cidaas.shared

// did load
override func viewDidLoad() {
super.viewDidLoad()
self.getRequestId()
}

// did receive memory warning
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

@IBAction func loginAction(_ sender: Any) {
Cidaas.shared.loginWithSocial(provider: "linkedin", delegate: self) {
// login with browser
func loginWithBrowser() {
self.cidaas.loginWithBrowser(delegate: self) {
switch $0 {
case .success(let loginSuccessResponse):
print(loginSuccessResponse.data.access_token)
break
case .failure(let loginErrorResponse):
print(loginErrorResponse.errorMessage)
case .failure(let loginFailureResponse):
print(loginFailureResponse.errorMessage)
break
}
}
}

// get request id
func getRequestId() {
self.cidaas.getRequestId() {
switch $0 {
case .success(let requestIdSuccessResponse):
print(requestIdSuccessResponse.data.requestId)
self.loginWithBrowser()
break
case .failure(let requestIdFailureResponse):
print(requestIdFailureResponse.errorMessage)
break
}
}
}

// get tenant information
func getTenantInformation() {
self.cidaas.getTenantInfo() {
switch $0 {
case .success(let tenantInfoSuccessResponse):
print(tenantInfoSuccessResponse.data.tenant_name)
break
case .failure(let tenantInfoFailureResponse):
print(tenantInfoFailureResponse.errorMessage)
break
}
}
}

// get client information
func getClientInformation() {
self.cidaas.getClientInfo() {
switch $0 {
case .success(let clientInfoSuccessResponse):
print(clientInfoSuccessResponse.data.login_providers)
break
case .failure(let clientInfoFailureResponse):
print(clientInfoFailureResponse.errorMessage)
break
}
}

// Cidaas.shared.loginWithBrowser(delegate: self) {
// switch $0 {
// case .failure(let errorResponse):
// print(errorResponse.errorMessage)
// break
// case .success(let successResponse):
// let alert = UIAlertController(title: "Access Token", message: "\(successResponse.data.access_token)", preferredStyle: .alert)
// alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
// self.present(alert, animated: true, completion: nil)
// break
// }
// }

// guard let url = URL(string: "https://stackoverflow.com") else { return }
// UIApplication.shared.open(url)

}
}
Loading

0 comments on commit 3db4602

Please sign in to comment.