diff --git a/Gigya.podspec b/Gigya.podspec index 89313c4b..0b07f22a 100644 --- a/Gigya.podspec +++ b/Gigya.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'Gigya' - spec.version = '1.1.4' + spec.version = '1.1.5' spec.license = 'Apache 2.0' spec.homepage = 'https://developers.gigya.com/display/GD/Swift+SDK' spec.author = 'Gigya SAP' @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| your Swift application DESC - spec.source = { :git => 'https://github.com/SAP/gigya-swift-sdk.git', :tag => 'core/v1.1.4' } + spec.source = { :git => 'https://github.com/SAP/gigya-swift-sdk.git', :tag => 'core/v1.1.5' } spec.module_name = 'Gigya' spec.swift_version = '5.3' diff --git a/GigyaAuth/GigyaAuth.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist b/GigyaAuth/GigyaAuth.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist index 14a99372..abbe1691 100644 --- a/GigyaAuth/GigyaAuth.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/GigyaAuth/GigyaAuth.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ GigyaAuth-Universal.xcscheme_^#shared#^_ orderHint - 9 + 8 GigyaAuth.xcscheme_^#shared#^_ orderHint - 8 + 7 diff --git a/GigyaE2ETestsApp/GigyaE2ETestsApp.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist b/GigyaE2ETestsApp/GigyaE2ETestsApp.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist index 9ae636f4..0d411dca 100644 --- a/GigyaE2ETestsApp/GigyaE2ETestsApp.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/GigyaE2ETestsApp/GigyaE2ETestsApp.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ GigyaE2ETestsApp.xcscheme_^#shared#^_ orderHint - 44 + 42 diff --git a/GigyaNssEngine/GigyaNssEngine.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist b/GigyaNssEngine/GigyaNssEngine.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist index 50bcee4d..57d412cb 100644 --- a/GigyaNssEngine/GigyaNssEngine.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/GigyaNssEngine/GigyaNssEngine.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ GigyaNssEngine-Universal-Debug.xcscheme_^#shared#^_ orderHint - 45 + 42 GigyaNssEngine-Universal-Release.xcscheme_^#shared#^_ @@ -20,18 +20,5 @@ 3 - SuppressBuildableAutocreation - - E7F8E2D723C73F00002A2A92 - - primary - - - E7F8E2E323C73F18002A2A92 - - primary - - - diff --git a/GigyaSwift.xcodeproj/project.pbxproj b/GigyaSwift.xcodeproj/project.pbxproj index 1f7b254f..998ce6c2 100644 --- a/GigyaSwift.xcodeproj/project.pbxproj +++ b/GigyaSwift.xcodeproj/project.pbxproj @@ -2273,7 +2273,7 @@ CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 78; + CURRENT_PROJECT_VERSION = 80; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 52P2295V75; DYLIB_COMPATIBILITY_VERSION = 1; @@ -2293,7 +2293,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.1.4; + MARKETING_VERSION = 1.1.5; MODULEMAP_FILE = ""; MODULEMAP_PRIVATE_FILE = ""; ONLY_ACTIVE_ARCH = NO; @@ -2330,7 +2330,7 @@ CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 78; + CURRENT_PROJECT_VERSION = 80; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 52P2295V75; DYLIB_COMPATIBILITY_VERSION = 1; @@ -2350,7 +2350,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.1.4; + MARKETING_VERSION = 1.1.5; MODULEMAP_FILE = ""; MODULEMAP_PRIVATE_FILE = ""; OTHER_LDFLAGS = ( diff --git a/GigyaSwift.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist b/GigyaSwift.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist index f45da8f5..3a4efa08 100644 --- a/GigyaSwift.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/GigyaSwift.xcodeproj/xcuserdata/i507698.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ Gigya.xcscheme_^#shared#^_ orderHint - 7 + 44 GigyaUITestsApp.xcscheme_^#shared#^_ @@ -17,7 +17,7 @@ TestApp.xcscheme_^#shared#^_ orderHint - 10 + 45 diff --git a/GigyaSwift/Gigya/GigyaCore.swift b/GigyaSwift/Gigya/GigyaCore.swift index dacb2597..410b2947 100644 --- a/GigyaSwift/Gigya/GigyaCore.swift +++ b/GigyaSwift/Gigya/GigyaCore.swift @@ -90,7 +90,7 @@ public final class GigyaCore: GigyaInstanceProtocol { config.apiDomain = apiDomain ?? self.defaultApiDomain config.apiKey = apiKey - businessApiService.getSDKConfig() + businessApiService.apiService.getSDKConfig() } // MARK: - Anonymous API @@ -146,6 +146,8 @@ public final class GigyaCore: GigyaInstanceProtocol { - returns: GigyaSession object. */ public func getSession() -> GigyaSession? { + guard isLoggedIn() else { return nil } + return sessionService.session } @@ -156,6 +158,13 @@ public final class GigyaCore: GigyaInstanceProtocol { sessionService.setClearCookies(to: value) } + /** + Override the default timeout for network requests. + */ + public func setRequestTimeout(to sec: Double) { + config.timestampOffset = sec + } + /** Logout of Gigya services. diff --git a/GigyaSwift/Global/Api/ApiService.swift b/GigyaSwift/Global/Api/ApiService.swift index b967de7b..6ca06d4b 100644 --- a/GigyaSwift/Global/Api/ApiService.swift +++ b/GigyaSwift/Global/Api/ApiService.swift @@ -17,13 +17,36 @@ final class ApiService: ApiServiceProtocol { private let networkAdapter: NetworkAdapterProtocol? - required init(with networkAdapter: NetworkAdapterProtocol, session: SessionServiceProtocol) { + private let persistenceService: PersistenceService + + required init(with networkAdapter: NetworkAdapterProtocol, session: SessionServiceProtocol, persistenceService: PersistenceService) { self.networkAdapter = networkAdapter self.sessionService = session + self.persistenceService = persistenceService + } + + func getSDKConfig() { + let params = ["include": "permissions,ids,appIds"] + let model = ApiRequestModel(method: GigyaDefinitions.API.getSdkConfig, params: params) + + self.sendBlocking(model: model, responseType: InitSdkResponseModel.self) { [weak self] result in + switch result { + case .success(let data): + self?.persistenceService.save(ids: data.ids) + self?.persistenceService.isInitSdk = true + case .failure(let error): + GigyaLogger.log(with: self, message: error.localizedDescription) + break + } + } } func send(model: ApiRequestModel, responseType: T.Type, completion: @escaping (GigyaApiResult) -> Void) { + if persistenceService.isInitSdk == false { + getSDKConfig() + } + send(model: model, responseType: responseType, blocking: false, completion: completion) } @@ -35,6 +58,7 @@ final class ApiService: ApiServiceProtocol { // Send request to server private func send(model: ApiRequestModel, responseType: T.Type, blocking: Bool, completion: @escaping (GigyaApiResult) -> Void) { + networkAdapter?.send(model: model, blocking: blocking) { [weak self] (data, error) in if error == nil { diff --git a/GigyaSwift/Global/Api/ApiServiceProtocol.swift b/GigyaSwift/Global/Api/ApiServiceProtocol.swift index 7d7ff620..3e13bf5e 100644 --- a/GigyaSwift/Global/Api/ApiServiceProtocol.swift +++ b/GigyaSwift/Global/Api/ApiServiceProtocol.swift @@ -10,10 +10,12 @@ import Foundation public protocol ApiServiceProtocol { - init(with requst: NetworkAdapterProtocol, session: SessionServiceProtocol) + init(with requst: NetworkAdapterProtocol, session: SessionServiceProtocol, persistenceService: PersistenceService) func sendBlocking(model: ApiRequestModel, responseType: T.Type, completion: @escaping (GigyaApiResult) -> Void) func send(model: ApiRequestModel, responseType: T.Type, completion: @escaping (GigyaApiResult) -> Void) + func getSDKConfig() + } diff --git a/GigyaSwift/Global/Api/BusinessApiService.swift b/GigyaSwift/Global/Api/BusinessApiService.swift index 3f2c9dcc..e2a6807e 100644 --- a/GigyaSwift/Global/Api/BusinessApiService.swift +++ b/GigyaSwift/Global/Api/BusinessApiService.swift @@ -48,23 +48,6 @@ class BusinessApiService: NSObject, BusinessApiServiceProtocol { self.interruptionsHandler = interruptionsHandler } - // Send regular request - func getSDKConfig() { - let params = ["include": "permissions,ids,appIds"] - let model = ApiRequestModel(method: GigyaDefinitions.API.getSdkConfig, params: params) - - apiService.sendBlocking(model: model, responseType: InitSdkResponseModel.self) { [weak self] result in - switch result { - case .success(let data): - self?.persistenceService.save(ids: data.ids) - self?.persistenceService.isInitSdk = true - case .failure(let error): - GigyaLogger.log(with: self, message: error.localizedDescription) - break - } - } - } - // Send regular request func send(api: String, params: [String: Any] = [:], completion: @escaping (GigyaApiResult) -> Void ) { let model = ApiRequestModel(method: api, params: params) diff --git a/GigyaSwift/Global/Api/BusinessApiServiceProtocol.swift b/GigyaSwift/Global/Api/BusinessApiServiceProtocol.swift index 53970997..a57efb1b 100644 --- a/GigyaSwift/Global/Api/BusinessApiServiceProtocol.swift +++ b/GigyaSwift/Global/Api/BusinessApiServiceProtocol.swift @@ -31,7 +31,6 @@ protocol BusinessApiServiceProtocol { biometricService: BiometricServiceInternalProtocol) func send(api: String, params: [String: Any], completion: @escaping (GigyaApiResult) -> Void) - func getSDKConfig() func send(dataType: T.Type, api: String, params: [String: Any], completion: @escaping (GigyaApiResult) -> Void) diff --git a/GigyaSwift/Global/PersistenceService.swift b/GigyaSwift/Global/PersistenceService.swift index 7095c567..8d8aaa64 100644 --- a/GigyaSwift/Global/PersistenceService.swift +++ b/GigyaSwift/Global/PersistenceService.swift @@ -8,7 +8,7 @@ import Foundation -final class PersistenceService { +public final class PersistenceService { var isInitSdk: Bool = false // MARK: - UserDefault diff --git a/GigyaSwift/Global/Resolvers/Tfa/TFAResolver.swift b/GigyaSwift/Global/Resolvers/Tfa/TFAResolver.swift index 7444a81b..cdabc23c 100644 --- a/GigyaSwift/Global/Resolvers/Tfa/TFAResolver.swift +++ b/GigyaSwift/Global/Resolvers/Tfa/TFAResolver.swift @@ -10,4 +10,8 @@ import Foundation open class TFAResolver: Resolver { public var gigyaAssertion: String? + + public required init(businessApiDelegate: BusinessApiDelegate, interruption: GigyaResponseModel, completionHandler: @escaping (GigyaLoginResult) -> Void) { + super.init(businessApiDelegate: businessApiDelegate, interruption: interruption, completionHandler: completionHandler) + } } diff --git a/GigyaSwift/Global/Utils/GigyaIOCContainer.swift b/GigyaSwift/Global/Utils/GigyaIOCContainer.swift index 975a9d10..520c9c62 100644 --- a/GigyaSwift/Global/Utils/GigyaIOCContainer.swift +++ b/GigyaSwift/Global/Utils/GigyaIOCContainer.swift @@ -86,8 +86,9 @@ final class GigyaIOCContainer: GigyaContainerProtocol { container.register(service: ApiServiceProtocol.self) { resolver in let sessionService = resolver.resolve(SessionServiceProtocol.self) + let persistenceService = resolver.resolve(PersistenceService.self) - return ApiService(with: resolver.resolve(NetworkAdapterProtocol.self)!, session: sessionService!) + return ApiService(with: resolver.resolve(NetworkAdapterProtocol.self)!, session: sessionService!, persistenceService: persistenceService!) } container.register(service: KeychainStorageFactory.self) { resolver in diff --git a/GigyaSwift/Global/Utils/SignatureUtils.swift b/GigyaSwift/Global/Utils/SignatureUtils.swift index 3f66db15..09b00469 100644 --- a/GigyaSwift/Global/Utils/SignatureUtils.swift +++ b/GigyaSwift/Global/Utils/SignatureUtils.swift @@ -46,7 +46,6 @@ class SignatureUtils { } } - if let session = session { let sig = hmac(algorithm: .SHA1, url: oauth1SignatureBaseString(config.apiDomain ,path, newParams), secret: session.secret) @@ -59,7 +58,7 @@ class SignatureUtils { private static func oauth1SignatureBaseString(_ domain: String ,_ sMethod: String, _ paramsToSend: [String: Any]) -> String { let method = "POST" let url = URL(string: "https://\(sMethod.components(separatedBy: ".").first!).\(domain)/\(sMethod)")! - let urlAllowed = NSCharacterSet(charactersIn: GigyaDefinitions.charactersAllowed).inverted + let urlAllowed = NSCharacterSet(charactersIn: GigyaDefinitions.charactersAllowedInSig).inverted let params = paramsToSend.mapValues { value in return "\(value)" } diff --git a/GigyaSwift/Models/Config/GigyaConfig.swift b/GigyaSwift/Models/Config/GigyaConfig.swift index 0ddf60fb..d02fc48f 100644 --- a/GigyaSwift/Models/Config/GigyaConfig.swift +++ b/GigyaSwift/Models/Config/GigyaConfig.swift @@ -19,4 +19,7 @@ public class GigyaConfig { public var sessionVerificationInterval: Double? internal var timestampOffset: Double = 0 + + internal var requestTimeout = InternalConfig.Network.requestTimeoutDefult + } diff --git a/GigyaSwift/Models/Config/GigyaDefinitions.swift b/GigyaSwift/Models/Config/GigyaDefinitions.swift index d906e702..ca9256cd 100644 --- a/GigyaSwift/Models/Config/GigyaDefinitions.swift +++ b/GigyaSwift/Models/Config/GigyaDefinitions.swift @@ -68,6 +68,7 @@ public struct GigyaDefinitions { public static let requestExpired = 403002 } - public static var charactersAllowed = "!*'|();/:@&=^+$,?%#[]{}\" " + public static var charactersAllowed = "!*'|();/:-_.@&=^+$,?%#[]{}\" " + public static var charactersAllowedInSig = "!*'|();/:@&=^+$,?%#\\[]{}\" " } diff --git a/GigyaSwift/Models/Config/InternalConfig.swift b/GigyaSwift/Models/Config/InternalConfig.swift index 2dc442c1..c191e8fc 100644 --- a/GigyaSwift/Models/Config/InternalConfig.swift +++ b/GigyaSwift/Models/Config/InternalConfig.swift @@ -10,7 +10,7 @@ import Foundation struct InternalConfig { struct General { - internal static let version = "ios_swift_1.1.4" + internal static let version = "ios_swift_1.1.5" internal static let sdkDomain = "com.gigya.GigyaSDK" internal static let defaultLang = "en" } @@ -32,4 +32,8 @@ struct InternalConfig { internal static let pushKey = "com.gigya.GigyaTfa:pushKey" } + + struct Network { + internal static let requestTimeoutDefult: Double = 60 + } } diff --git a/GigyaSwift/Network/Models/GigyaRequestSignature.swift b/GigyaSwift/Network/Models/GigyaRequestSignature.swift index 2b33babc..97426646 100644 --- a/GigyaSwift/Network/Models/GigyaRequestSignature.swift +++ b/GigyaSwift/Network/Models/GigyaRequestSignature.swift @@ -9,7 +9,7 @@ import Foundation struct GigyaRequestSignature: Codable { - var apikey: String + var apikey: String? var format: String = "json" var gmid: String? var ucid: String? @@ -23,11 +23,14 @@ struct GigyaRequestSignature: Codable { init(oauthToken: String?, apikey: String, nonce: String?, timestamp: String?, ucid: String?, gmid: String?) { self.oauthToken = oauthToken - self.apikey = apikey self.nonce = nonce self.timestamp = timestamp self.ucid = ucid self.gmid = gmid + + if oauthToken == nil { + self.apikey = apikey + } } init(apikey: String, ucid: String?, gmid: String?) { diff --git a/GigyaSwift/Network/Service/NetworkProvider.swift b/GigyaSwift/Network/Service/NetworkProvider.swift index 079cc5a8..2e23dd24 100644 --- a/GigyaSwift/Network/Service/NetworkProvider.swift +++ b/GigyaSwift/Network/Service/NetworkProvider.swift @@ -40,6 +40,7 @@ final class NetworkProvider { dataURL.appendPathComponent(model.method) var request: URLRequest = URLRequest(url: dataURL) + request.timeoutInterval = TimeInterval(config?.requestTimeout ?? InternalConfig.Network.requestTimeoutDefult) // Encode body request to params do { @@ -53,7 +54,7 @@ final class NetworkProvider { request.httpBody = bodyString.dropLast().data(using: .utf8) - GigyaLogger.log(with: self, message: "[Request]:httpBody, jsonData: \(bodyDataParmas)") + GigyaLogger.log(with: self, message: "[Request]:httpBody, jsonData: \(bodyString)") } catch { GigyaLogger.log(with: self, message: "Error: \(NetworkError.createURLRequestFailed.localizedDescription)")