Skip to content

Commit 4be73d3

Browse files
authored
Issue p2#359: Access to ASWebAuthenticationSession-prefersEphemeralWebBrowserSession (p2#366)
1 parent 7acf3fe commit 4be73d3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/Base/OAuth2AuthConfig.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public struct OAuth2AuthConfig {
4646
/// Starting with iOS 12, `ASWebAuthenticationSession` can be used for embedded authorization instead of our custom class. You can turn this on here.
4747
public var useAuthenticationSession = false
4848

49+
/// May be passed through to [ASWebAuthenticationSession](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/3237231-prefersephemeralwebbrowsersessio).
50+
public var prefersEphemeralWebBrowserSession = false
51+
4952
#if os(iOS)
5053
/// By assigning your own style you can configure how the embedded authorization is presented.
5154
public var modalPresentationStyle = UIModalPresentationStyle.fullScreen

Sources/iOS/OAuth2Authorizer+iOS.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
8383
throw OAuth2Error.noRedirectURL
8484
}
8585

86-
authenticationSessionEmbedded(at: url, withRedirect: redirect)
86+
authenticationSessionEmbedded(at: url, withRedirect: redirect, prefersEphemeralWebBrowserSession: config.ui.prefersEphemeralWebBrowserSession)
8787
} else {
8888
guard let controller = config.authorizeContext as? UIViewController else {
8989
throw (nil == config.authorizeContext) ? OAuth2Error.noAuthorizationContext : OAuth2Error.invalidAuthorizationContext
@@ -132,11 +132,12 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
132132

133133
- parameter at: The authorize URL to open
134134
- parameter redirect: The full redirect URL to use
135+
- parameter prefersEphemeralWebBrowserSession: may be passed through to [ASWebAuthenticationSession](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/3237231-prefersephemeralwebbrowsersessio).
135136
- returns: A Boolean value indicating whether the web authentication session starts successfully.
136137
*/
137138
@available(iOS 11.0, *)
138139
@discardableResult
139-
public func authenticationSessionEmbedded(at url: URL, withRedirect redirect: String) -> Bool {
140+
public func authenticationSessionEmbedded(at url: URL, withRedirect redirect: String, prefersEphemeralWebBrowserSession prefersEphemeralWebBrowserSession: Bool = false) -> Bool {
140141
guard let redirectURL = URL(string: redirect) else {
141142
oauth2.logger?.warn("OAuth2", msg: "Unable to parse redirect URL ”(redirect)“")
142143
return false
@@ -174,7 +175,10 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
174175
authenticationSession = ASWebAuthenticationSession(url: url, callbackURLScheme: redirectURL.scheme, completionHandler: completionHandler)
175176
if #available(iOS 13.0, *) {
176177
webAuthenticationPresentationContextProvider = OAuth2ASWebAuthenticationPresentationContextProvider(authorizer: self)
177-
(authenticationSession as! ASWebAuthenticationSession).presentationContextProvider = webAuthenticationPresentationContextProvider as! OAuth2ASWebAuthenticationPresentationContextProvider
178+
if let session = authenticationSession as? ASWebAuthenticationSession {
179+
session.presentationContextProvider = webAuthenticationPresentationContextProvider as! OAuth2ASWebAuthenticationPresentationContextProvider
180+
session.prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession
181+
}
178182
}
179183
return (authenticationSession as! ASWebAuthenticationSession).start()
180184
} else {

0 commit comments

Comments
 (0)