Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sagishm committed Oct 5, 2020
2 parents 88e2b3c + bf77eeb commit fbc392d
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Gigya.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<key>GigyaAuth-Universal.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>9</integer>
<integer>8</integer>
</dict>
<key>GigyaAuth.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>7</integer>
</dict>
</dict>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>GigyaE2ETestsApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>44</integer>
<integer>42</integer>
</dict>
</dict>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>GigyaNssEngine-Universal-Debug.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>45</integer>
<integer>42</integer>
</dict>
<key>GigyaNssEngine-Universal-Release.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -20,18 +20,5 @@
<integer>3</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>E7F8E2D723C73F00002A2A92</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>E7F8E2E323C73F18002A2A92</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
8 changes: 4 additions & 4 deletions GigyaSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>Gigya.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>44</integer>
</dict>
<key>GigyaUITestsApp.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -17,7 +17,7 @@
<key>TestApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>10</integer>
<integer>45</integer>
</dict>
</dict>
</dict>
Expand Down
11 changes: 10 additions & 1 deletion GigyaSwift/Gigya/GigyaCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final class GigyaCore<T: GigyaAccountProtocol>: GigyaInstanceProtocol {
config.apiDomain = apiDomain ?? self.defaultApiDomain
config.apiKey = apiKey

businessApiService.getSDKConfig()
businessApiService.apiService.getSDKConfig()
}

// MARK: - Anonymous API
Expand Down Expand Up @@ -146,6 +146,8 @@ public final class GigyaCore<T: GigyaAccountProtocol>: GigyaInstanceProtocol {
- returns: GigyaSession object.
*/
public func getSession() -> GigyaSession? {
guard isLoggedIn() else { return nil }

return sessionService.session
}

Expand All @@ -156,6 +158,13 @@ public final class GigyaCore<T: GigyaAccountProtocol>: 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.
Expand Down
26 changes: 25 additions & 1 deletion GigyaSwift/Global/Api/ApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Codable>(model: ApiRequestModel, responseType: T.Type,
completion: @escaping (GigyaApiResult<T>) -> Void) {
if persistenceService.isInitSdk == false {
getSDKConfig()
}

send(model: model, responseType: responseType, blocking: false, completion: completion)
}

Expand All @@ -35,6 +58,7 @@ final class ApiService: ApiServiceProtocol {
// Send request to server
private func send<T: Codable>(model: ApiRequestModel, responseType: T.Type, blocking: Bool,
completion: @escaping (GigyaApiResult<T>) -> Void) {

networkAdapter?.send(model: model, blocking: blocking) { [weak self] (data, error) in

if error == nil {
Expand Down
4 changes: 3 additions & 1 deletion GigyaSwift/Global/Api/ApiServiceProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Codable & Any>(model: ApiRequestModel, responseType: T.Type, completion: @escaping (GigyaApiResult<T>) -> Void)

func send<T: Codable & Any>(model: ApiRequestModel, responseType: T.Type, completion: @escaping (GigyaApiResult<T>) -> Void)

func getSDKConfig()

}
17 changes: 0 additions & 17 deletions GigyaSwift/Global/Api/BusinessApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<GigyaDictionary>) -> Void ) {
let model = ApiRequestModel(method: api, params: params)
Expand Down
1 change: 0 additions & 1 deletion GigyaSwift/Global/Api/BusinessApiServiceProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ protocol BusinessApiServiceProtocol {
biometricService: BiometricServiceInternalProtocol)

func send(api: String, params: [String: Any], completion: @escaping (GigyaApiResult<GigyaDictionary>) -> Void)
func getSDKConfig()

func send<T: Codable>(dataType: T.Type, api: String, params: [String: Any], completion: @escaping (GigyaApiResult<T>) -> Void)

Expand Down
2 changes: 1 addition & 1 deletion GigyaSwift/Global/PersistenceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

final class PersistenceService {
public final class PersistenceService {
var isInitSdk: Bool = false

// MARK: - UserDefault
Expand Down
4 changes: 4 additions & 0 deletions GigyaSwift/Global/Resolvers/Tfa/TFAResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ import Foundation

open class TFAResolver<T: GigyaAccountProtocol>: Resolver<T> {
public var gigyaAssertion: String?

public required init(businessApiDelegate: BusinessApiDelegate, interruption: GigyaResponseModel, completionHandler: @escaping (GigyaLoginResult<T>) -> Void) {
super.init(businessApiDelegate: businessApiDelegate, interruption: interruption, completionHandler: completionHandler)
}
}
3 changes: 2 additions & 1 deletion GigyaSwift/Global/Utils/GigyaIOCContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ final class GigyaIOCContainer<T: GigyaAccountProtocol>: 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
Expand Down
3 changes: 1 addition & 2 deletions GigyaSwift/Global/Utils/SignatureUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class SignatureUtils {
}
}


if let session = session {
let sig = hmac(algorithm: .SHA1, url: oauth1SignatureBaseString(config.apiDomain ,path, newParams), secret: session.secret)

Expand All @@ -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)" }

Expand Down
3 changes: 3 additions & 0 deletions GigyaSwift/Models/Config/GigyaConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public class GigyaConfig {
public var sessionVerificationInterval: Double?

internal var timestampOffset: Double = 0

internal var requestTimeout = InternalConfig.Network.requestTimeoutDefult

}
3 changes: 2 additions & 1 deletion GigyaSwift/Models/Config/GigyaDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public struct GigyaDefinitions {
public static let requestExpired = 403002
}

public static var charactersAllowed = "!*'|();/:@&=^+$,?%#[]{}\" "
public static var charactersAllowed = "!*'|();/:-_.@&=^+$,?%#[]{}\" "
public static var charactersAllowedInSig = "!*'|();/:@&=^+$,?%#\\[]{}\" "

}
6 changes: 5 additions & 1 deletion GigyaSwift/Models/Config/InternalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -32,4 +32,8 @@ struct InternalConfig {
internal static let pushKey = "com.gigya.GigyaTfa:pushKey"

}

struct Network {
internal static let requestTimeoutDefult: Double = 60
}
}
7 changes: 5 additions & 2 deletions GigyaSwift/Network/Models/GigyaRequestSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?) {
Expand Down
3 changes: 2 additions & 1 deletion GigyaSwift/Network/Service/NetworkProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)")
Expand Down

0 comments on commit fbc392d

Please sign in to comment.