diff --git a/FronteggSwift.podspec b/FronteggSwift.podspec index 40b34e3..7d4148c 100644 --- a/FronteggSwift.podspec +++ b/FronteggSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'FronteggSwift' - s.version = '1.1.0' + s.version = '1.1.1' s.summary = 'A swift library for easy integrating iOS application with Frontegg Services' s.description = 'Frontegg is an end-to-end user management platform for B2B SaaS, powering strategies from PLG to enterprise readiness. Easy migration, no credit card required' s.homepage = 'https://github.com/frontegg/frontegg-ios-swift' diff --git a/Sources/FronteggSwift/embedded/CustomWebView.swift b/Sources/FronteggSwift/embedded/CustomWebView.swift index 960c43b..e12d20e 100644 --- a/Sources/FronteggSwift/embedded/CustomWebView.swift +++ b/Sources/FronteggSwift/embedded/CustomWebView.swift @@ -32,10 +32,10 @@ class CustomWebView: WKWebView, WKNavigationDelegate { logger.info("urlType: \(urlType)") switch(urlType){ - case .SocialLoginRedirectToBrowser: do { - - return self.handleSocialLoginRedirectToBrowser(webView, url) - } +// case .SocialLoginRedirectToBrowser: do { +// +// return self.handleSocialLoginRedirectToBrowser(webView, url) +// } case .HostedLoginCallback: do { return self.handleHostedLoginCallback(webView, url) } @@ -184,7 +184,7 @@ class CustomWebView: WKWebView, WKNavigationDelegate { logger.trace("setSocialLoginRedirectUri()") let queryItems = [ - URLQueryItem(name: "redirectUri", value: generateRedirectUri()), + URLQueryItem(name: "redirectUri", value: generateRedirectUri()) ] var urlComps = URLComponents(string: url.absoluteString)! @@ -197,7 +197,37 @@ class CustomWebView: WKWebView, WKNavigationDelegate { logger.trace("added redirectUri to socialLogin auth url \(urlComps.url!)") - _ = webView.load(URLRequest(url: urlComps.url!)) +// _ = webView.load(URLRequest(url: urlComps.url!)) + + let followUrl = urlComps.url! + DispatchQueue.global(qos: .background).async { + var request = URLRequest(url: followUrl) + request.httpMethod = "GET" + + let noRedirectDelegate = NoRedirectSessionDelegate() + let noRedirectSession = URLSession(configuration: .default, delegate: noRedirectDelegate, delegateQueue: nil) + + let task = noRedirectSession.dataTask(with: request) { (data, response, error) in + // Check for errors + if let error = error { + print("Error: \(error.localizedDescription)") + return + } + + // Check for valid HTTP response + if let httpResponse = response as? HTTPURLResponse { + + if let location = httpResponse.value(forHTTPHeaderField: "Location"), + let socialLoginUrl = URL(string: location){ + + self.handleSocialLoginRedirectToBrowser(webView, socialLoginUrl) + } + + } + } + task.resume() + } + return .cancel } @@ -212,7 +242,6 @@ class CustomWebView: WKWebView, WKNavigationDelegate { let url = urlComps.url! - fronteggAuth.webLoading = false fronteggAuth.webAuthentication.webAuthSession?.cancel() fronteggAuth.webAuthentication = WebAuthentication() diff --git a/Sources/FronteggSwift/utils/NoRedirectSessionDelegate.swift b/Sources/FronteggSwift/utils/NoRedirectSessionDelegate.swift new file mode 100644 index 0000000..333d7e8 --- /dev/null +++ b/Sources/FronteggSwift/utils/NoRedirectSessionDelegate.swift @@ -0,0 +1,16 @@ +// +// NoRedirectSessionDelegate.swift +// +// +// Created by David Frontegg on 24/10/2023. +// + +import Foundation + + +class NoRedirectSessionDelegate: NSObject, URLSessionTaskDelegate { + func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) { + // Returning nil will prevent the redirect + completionHandler(nil) + } +} diff --git a/Sources/FronteggSwift/utils/UrlHelper.swift b/Sources/FronteggSwift/utils/UrlHelper.swift index 4cee676..f5d92f1 100644 --- a/Sources/FronteggSwift/utils/UrlHelper.swift +++ b/Sources/FronteggSwift/utils/UrlHelper.swift @@ -118,9 +118,9 @@ func getOverrideUrlType (url: URL) -> OverrideUrlType { if(url.absoluteString.starts(with: generateRedirectUri())){ return .HostedLoginCallback } - if((URLConstants.oauthUrls.first { urlStr.hasPrefix($0)}) != nil) { - return .SocialLoginRedirectToBrowser - } +// if((URLConstants.oauthUrls.first { urlStr.hasPrefix($0)}) != nil) { +// return .SocialLoginRedirectToBrowser +// } return .Unknown