Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sagishm committed Feb 14, 2023
2 parents 81989f9 + 65f1f8e commit 816e363
Show file tree
Hide file tree
Showing 22 changed files with 481 additions and 56 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.4.2'
spec.version = '1.5.0'
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.4.2' }
spec.source = { :git => 'https://github.com/SAP/gigya-swift-sdk.git', :tag => 'core/v1.5.0' }
spec.module_name = 'Gigya'
spec.swift_version = '5.3'

Expand Down
4 changes: 2 additions & 2 deletions GigyaSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.5.0;
MODULEMAP_FILE = "";
MODULEMAP_PRIVATE_FILE = "";
ONLY_ACTIVE_ARCH = NO;
Expand Down Expand Up @@ -2651,7 +2651,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.5.0;
MODULEMAP_FILE = "";
MODULEMAP_PRIVATE_FILE = "";
ONLY_ACTIVE_ARCH = NO;
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions GigyaSwift/Gigya/GigyaCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class GigyaCore<T: GigyaAccountProtocol>: GigyaInstanceProtocol {
return self.container.resolve(PushNotificationsServiceProtocol.self)!
}()

private var pluginViewWrapper: PluginViewWrapper<T>?

private let container: IOCContainer

// MARK: - Biometric service
Expand Down Expand Up @@ -73,9 +75,12 @@ public final class GigyaCore<T: GigyaAccountProtocol>: GigyaInstanceProtocol {

// load plist and make init
let plistConfig = plistFactory.parsePlistConfig()


// load cname data
config.cname = plistConfig?.cname

if let apiKey = plistConfig?.apiKey, !apiKey.isEmpty {
initFor(apiKey: apiKey, apiDomain: plistConfig?.apiDomain)
initFor(apiKey: apiKey, apiDomain: plistConfig?.apiDomain, cname: plistConfig?.cname)
}

if let accountConfig: GigyaAccountConfig = plistConfig?.account {
Expand All @@ -96,15 +101,17 @@ public final class GigyaCore<T: GigyaAccountProtocol>: GigyaInstanceProtocol {
- Parameter apiKey: Client API-KEY
- Parameter apiDomain: Request Domain.
- Parameter cname: Custom cname domain.
*/

public func initFor(apiKey: String, apiDomain: String? = nil) {
public func initFor(apiKey: String, apiDomain: String? = nil, cname: String? = nil) {
guard !apiKey.isEmpty else {
GigyaLogger.error(with: Gigya.self, message: "please make sure you call 'initWithApi' or add apiKey to plist file")
}

config.apiDomain = apiDomain ?? self.defaultApiDomain
config.apiKey = apiKey
config.cname = cname

businessApiService.apiService.getSDKConfig()
}
Expand Down Expand Up @@ -427,10 +434,14 @@ public final class GigyaCore<T: GigyaAccountProtocol>: GigyaInstanceProtocol {
*/

public func showScreenSet(with name: String, viewController: UIViewController, params: [String: Any] = [:], completion: @escaping (GigyaPluginEvent<T>) -> Void) {
let webBridge = createWebBridge()
var webBridge = createWebBridge()

let wrapper = PluginViewWrapper(config: config, persistenceService: persistenceService, sessionService: sessionService, businessApiService: businessApiService, webBridge: webBridge, plugin: "accounts.screenSet", params: params, completion: completion)
wrapper.presentPluginController(viewController: viewController, dataType: T.self, screenSet: name)
pluginViewWrapper = PluginViewWrapper(config: config, persistenceService: persistenceService, sessionService: sessionService, businessApiService: businessApiService, webBridge: webBridge, plugin: "accounts.screenSet", params: params, completion: completion)
pluginViewWrapper?.presentPluginController(viewController: viewController, dataType: T.self, screenSet: name)

pluginViewWrapper?.didFinish = { [weak self] in
self?.pluginViewWrapper = nil
}
}

// MARK: - Interruptions
Expand Down
18 changes: 10 additions & 8 deletions GigyaSwift/Global/Plugins/GigyaWebBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import WebKit
The `GigyaWebBridge` acts as the optimal bridge between the Gigya webSdk and the iOS sdk. Supporting complex flows such as screensets, saml etc.
*/

public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageHandler {
final public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageHandler {

let config: GigyaConfig

Expand All @@ -27,7 +27,7 @@ public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageH
let contentController = WKUserContentController()

var webView: WKWebView?
weak var viewController: UIViewController?
var viewController: UIViewController?

let JSEventHandler = "gsapi"
let baseURL = "https://www.gigya.com"
Expand Down Expand Up @@ -58,6 +58,7 @@ public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageH
*/


public func attachTo(webView: WKWebView, viewController: UIViewController, pluginEvent: @escaping (GigyaPluginEvent<T>) -> Void) {
guard let apikey = config.apiKey else { return }

Expand Down Expand Up @@ -296,8 +297,7 @@ public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageH

self.businessApiService.accountService.account = dataEncoded

// self.completion(.onLogin(account: dataEncoded))
self.interruptionManager.responseManager(params: params, data: dataEncoded, completion: self.completion)
self.interruptionManager.responseManager(apiMethod: apiMethod, params: params, data: dataEncoded, completion: self.completion)
} catch let error {
self.invokeError(callbackId: "internal", error: .jsonParsingError(error: error))

Expand Down Expand Up @@ -332,8 +332,7 @@ public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageH

self.businessApiService.accountService.account = data

self.interruptionManager.responseManager(params: params, data: data, completion: self.completion)
// self.completion(.onLogin(account: data))
self.interruptionManager.responseManager(apiMethod: apiMethod, params: params, data: data, completion: self.completion)
case .failure(let error):
GigyaLogger.log(with: self, message: "sendLoginRequest: error:\n\(error.localizedDescription)")
self.interruptionManager.interruptionHandler(error: error)
Expand Down Expand Up @@ -429,7 +428,7 @@ public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageH
let dataEncoded = try? DecodeEncodeUtils.encodeToDictionary(obj: data)
self.invokeCallback(callbackId: callbackId, and: dataEncoded!.asJson)

self.interruptionManager.responseManager(params: params, data: data, completion: self.completion)
self.interruptionManager.responseManager(apiMethod: apiMethod, params: params, data: data, completion: self.completion)

case .failure(let data):
GigyaLogger.log(with: self, message: "sendOauthRequest: error:\n\(data.error.localizedDescription)")
Expand Down Expand Up @@ -467,5 +466,8 @@ public class GigyaWebBridge<T: GigyaAccountProtocol>: NSObject, WKScriptMessageH
}
}
}


deinit {
GigyaLogger.log(with: self, message: "deinit")
}
}
17 changes: 11 additions & 6 deletions GigyaSwift/Global/Plugins/PluginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ final class PluginViewController<T: GigyaAccountProtocol>: GigyaWebViewControlle

let contentController = WKUserContentController()

var webBridge: GigyaWebBridge<T>
var webBridge: GigyaWebBridge<T>?

let pluginEvent: (GigyaPluginEvent<T>) -> Void

init(webBridge: GigyaWebBridge<T>, pluginEvent: @escaping (GigyaPluginEvent<T>) -> Void) {
init(webBridge: GigyaWebBridge<T>?, pluginEvent: @escaping (GigyaPluginEvent<T>) -> Void) {
self.webBridge = webBridge
self.pluginEvent = pluginEvent

Expand All @@ -28,14 +28,14 @@ final class PluginViewController<T: GigyaAccountProtocol>: GigyaWebViewControlle

super.init(configuration: webViewConfiguration)

self.webBridge.attachTo(webView: self.webView, viewController: self, pluginEvent: pluginEvent)
self.webBridge?.attachTo(webView: self.webView, viewController: self, pluginEvent: pluginEvent)

self.webBridge.viewController = self
self.webBridge?.viewController = self
self.webView.navigationDelegate = self
self.webView.uiDelegate = self

userDidCancel = {
pluginEvent(.onCanceled)
userDidCancel = { [weak self] in
self?.pluginEvent(.onCanceled)
}
}

Expand Down Expand Up @@ -72,6 +72,11 @@ final class PluginViewController<T: GigyaAccountProtocol>: GigyaWebViewControlle
}

deinit {
self.contentController.removeAllUserScripts()
if #available(iOS 14.0, *) {
self.contentController.removeAllScriptMessageHandlers()
}

GigyaLogger.log(with: self, message: "deinit")
}
}
29 changes: 23 additions & 6 deletions GigyaSwift/Global/Plugins/PluginViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class PluginViewWrapper<T: GigyaAccountProtocol>: PluginViewWrapperProtocol {

let businessApiService: BusinessApiServiceProtocol

let webBridge: GigyaWebBridge<T>
var webBridge: GigyaWebBridge<T>?

var completion: (GigyaPluginEvent<T>) -> Void?

var plugin: String

var params: [String:Any]

var eventHandler: ((GigyaPluginEvent<T>) -> Void)?

var didFinish: () -> Void = { }

init(config: GigyaConfig, persistenceService: PersistenceService, sessionService: SessionServiceProtocol, businessApiService: BusinessApiServiceProtocol, webBridge: GigyaWebBridge<T>,
plugin: String, params: [String: Any], completion: @escaping (GigyaPluginEvent<T>) -> Void) {
Expand Down Expand Up @@ -60,25 +64,34 @@ class PluginViewWrapper<T: GigyaAccountProtocol>: PluginViewWrapperProtocol {
var pluginViewController: PluginViewController<T>?

// make completionHandler to know when need to dismiss viewController
let eventHandler: (GigyaPluginEvent<T>) -> Void = { result in
eventHandler = { [weak self] result in
switch result {
case .onHide, .onCanceled:
pluginViewController?.webView.uiDelegate = nil
pluginViewController?.webView.navigationDelegate = nil
pluginViewController?.dismiss(animated: true, completion: nil)
pluginViewController = nil
self?.eventHandler = nil
self?.webBridge?.webView = nil
self?.webBridge?.viewController = nil
self?.webBridge = nil
self?.completion(result)
self?.didFinish()
default:
break
}

self.completion(result)
self?.completion(result)
}

// Present plugin view controller.

pluginViewController = PluginViewController(webBridge: webBridge, pluginEvent: eventHandler)
pluginViewController = PluginViewController(webBridge: webBridge, pluginEvent: eventHandler!)

let navigationController = UINavigationController(rootViewController: pluginViewController!)

viewController.present(navigationController, animated: true) {
self.webBridge.load(html: html)
self.webBridge?.load(html: html)
}
}

Expand Down Expand Up @@ -127,7 +140,7 @@ class PluginViewWrapper<T: GigyaAccountProtocol>: PluginViewWrapperProtocol {
document.location.href = 'gsapi://on_js_load_error';
}, 10000);
</script>
<script src='https://cdns.\(apiDomain)/JS/gigya.js?apikey=\(apiKey)&lang=\(lang)&debug=1' type='text/javascript' onLoad='onJSLoad();'>
<script src='https://\(config.cnameEnable ? "" : "cdns.")\(apiDomain)/JS/gigya.js?apikey=\(apiKey)&lang=\(lang)&debug=1' type='text/javascript' onLoad='onJSLoad();'>
{
deviceType: 'mobile' // consoleLogLevel: 'error'
}
Expand All @@ -145,4 +158,8 @@ class PluginViewWrapper<T: GigyaAccountProtocol>: PluginViewWrapperProtocol {
"""
return html
}

deinit {
GigyaLogger.log(with: self, message: "deinit")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
protocol WebBridgeResolver: BaseResolver {
init(busnessApi: BusinessApiDelegate, dispose: @escaping () -> Void)

func resolve<T: GigyaAccountProtocol>(params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void)
func resolve<T: GigyaAccountProtocol>(apiMethod: String, params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void)
}

class WebBridgeFroceLoginResolver: WebBridgeResolver {
Expand All @@ -24,8 +24,8 @@ class WebBridgeFroceLoginResolver: WebBridgeResolver {
self.busnessApi = busnessApi
}

func resolve<T: GigyaAccountProtocol>(params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void) {
if params["loginMode"] == "connect" {
func resolve<T: GigyaAccountProtocol>(apiMethod: String, params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void) {
if params["loginMode"] == "connect" || apiMethod == GigyaDefinitions.API.finalizeRegistration {
busnessApi.callGetAccount(dataType: T.self, params: [:], clearAccount: true) { [weak self] result in
switch result {
case .success(data: let userdata):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum WebBridgeInterruption: Int {
protocol WebBridgeInterruptionResolverFactoryProtocol {
func interruptionHandler(error: NetworkError)

func responseManager<T: GigyaAccountProtocol>(params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void)
func responseManager<T: GigyaAccountProtocol>(apiMethod: String, params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void)
}

class WebBridgeInterruptionManager: WebBridgeInterruptionResolverFactoryProtocol {
Expand All @@ -35,13 +35,13 @@ class WebBridgeInterruptionManager: WebBridgeInterruptionResolverFactoryProtocol
self.busnessApi = busnessApi
}

func responseManager<T: GigyaAccountProtocol>(params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void) {
func responseManager<T: GigyaAccountProtocol>(apiMethod: String, params: [String: String], data: T, completion: @escaping (GigyaPluginEvent<T>) -> Void) {
guard let resolver = resolver else {
completion(.onLogin(account: data))
return
}

resolver.resolve(params: params, data: data, completion: completion)
resolver.resolve(apiMethod: apiMethod, params: params, data: data, completion: completion)
}

func interruptionHandler(error: NetworkError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ProvidersLoginWrapper: NSObject {
let disabledProviders = params?["disabledProviders"] ?? ""

let providersString = providers.filter { $0.isSupported() }.map { "\($0)" }.joined(separator: ",")
var urlString = "https://socialize.\(config?.apiDomain ?? "")/gs/mobile/LoginUI.aspx?"
var urlString = "https://\(config?.cnameEnable ?? false ? "" : "socialize.")\(config?.apiDomain ?? "")/gs/mobile/LoginUI.aspx?"
urlString.append("redirect_uri=gsapi://result&")
urlString.append("requestType=login&")
urlString.append("iosVersion=\(UIDevice.current.systemVersion)&")
Expand Down
2 changes: 1 addition & 1 deletion GigyaSwift/Global/Providers/WebLogin/SsoLoginWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class SsoLoginWrapper: NSObject, ProviderWrapperProtocol {
}

private func getUrl(path: String = "") -> String {
return "\(EndPoints.fidmUrl)\(self.config?.apiDomain ?? "")\(EndPoints.loginPath)\(self.config?.apiKey ?? "")/\(path)"
return "\(config!.cnameEnable ? "https://": EndPoints.fidmUrl)\(self.config?.apiDomain ?? "")\(EndPoints.loginPath)\(self.config?.apiKey ?? "")/\(path)"
}

private func getSessionFrom(code: String) {
Expand Down
2 changes: 1 addition & 1 deletion GigyaSwift/Global/Providers/WebLogin/WebViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class WebLoginWrapper: NSObject, ProviderWrapperProtocol {
loginPath = "socialize.addConnection"
}

let urlString = "https://socialize.\(config?.apiDomain ?? "")/\(loginPath)"
let urlString = "https://\(config?.cnameEnable ?? false ? "" : "socialize.")\(config?.apiDomain ?? "")/\(loginPath)"

var serverParams: [String: Any] = [:]
serverParams["redirect_uri"] = "gsapi://login_result"
Expand Down
2 changes: 1 addition & 1 deletion GigyaSwift/Global/ReportingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class ReportingService {
return
}

let url = "https://accounts.\(config.apiDomain)/"
let url = "https://accounts.\(config._apiDomain ?? "")"
let params: [String: Any] = [
"message": msg,
"details": details,
Expand Down
4 changes: 2 additions & 2 deletions GigyaSwift/Global/Utils/SignatureUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SignatureUtils {
}

if let session = session {
let sig = hmac(algorithm: .SHA1, url: oauth1SignatureBaseString(config.apiDomain ,path, newParams), secret: session.secret)
let sig = hmac(algorithm: .SHA1, url: oauth1SignatureBaseString(config.cnameEnable ? config.cname! : "\(path.components(separatedBy: ".").first!).\(config.apiDomain)" ,path, newParams), secret: session.secret)

newParams["sig"] = sig
}
Expand All @@ -59,7 +59,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 url = URL(string: "https://\(domain)/\(sMethod)")!
let urlAllowed = NSCharacterSet(charactersIn: GigyaDefinitions.charactersAllowedInSig).inverted

let params = paramsToSend.mapValues { value in return "\(value)" }
Expand Down
Loading

0 comments on commit 816e363

Please sign in to comment.