Skip to content

Commit

Permalink
Merge pull request #236 from ForgeRock/SDKS-2707-ephemeral-authSession
Browse files Browse the repository at this point in the history
Add a new ephemeralAuthSession browser type
  • Loading branch information
spetrov authored Oct 3, 2023
2 parents 278e93a + 1fa123b commit 3e8867c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions FRAuth/FRAuth/User/Browser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Browser.swift
// FRAuth
//
// Copyright (c) 2020-2021 ForgeRock. All rights reserved.
// Copyright (c) 2020-2023 ForgeRock. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
Expand All @@ -20,6 +20,9 @@ import SafariServices
case nativeBrowserApp = 1
case sfViewController = 2
case authSession = 0

@available(iOS 13, *)
case ephemeralAuthSession = 3
}


Expand Down Expand Up @@ -127,8 +130,14 @@ import SafariServices
}
}
else {
var prefersEphemeralWebBrowserSession = false
if #available(iOS 13.0, *) {
if self.browserType == .ephemeralAuthSession {
prefersEphemeralWebBrowserSession = true
}
}
if #available(iOS 12.0, *) {
self.isInProgress = self.loginWithASWebSession(url: url, completion: completion)
self.isInProgress = self.loginWithASWebSession(url: url, prefersEphemeralWebBrowserSession: prefersEphemeralWebBrowserSession, completion: completion)
}
else if #available(iOS 11.0, *) {
self.isInProgress = self.loginWithSFWebSession(url: url, completion: completion)
Expand Down Expand Up @@ -243,10 +252,11 @@ import SafariServices
/// Performs authentication through /authorize endpoint using ASWebAuthenticationSession
/// - Parameters:
/// - url: URL of /authorize including all URL query parameter
/// - prefersEphemeralWebBrowserSession: (iOS 13 +) Indicates whether the session should ask the browser for an ephemeral session.
/// - completion: Completion callback to nofiy the result
/// - Returns: Boolean indicator whether or not launching external user-agent was successful
@available(iOS 12.0, *)
func loginWithASWebSession(url: URL, completion: @escaping UserCallback) -> Bool {
func loginWithASWebSession(url: URL, prefersEphemeralWebBrowserSession: Bool, completion: @escaping UserCallback) -> Bool {
let asWebAuthSession = ASWebAuthenticationSession(url: url, callbackURLScheme: self.oAuth2Client.redirectUri.scheme) { (url, error) in

if let error = error {
Expand All @@ -269,6 +279,7 @@ import SafariServices
// Provide Context Provider with given viewController for iOS 13 or above
if #available(iOS 13.0, *) {
asWebAuthSession.presentationContextProvider = self
asWebAuthSession.prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession
}
self.currentSession = asWebAuthSession
return asWebAuthSession.start()
Expand Down

0 comments on commit 3e8867c

Please sign in to comment.