@@ -42,10 +42,10 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
4242
4343 /// Used to store the authentication session.
4444 private var authenticationSession : AnyObject ?
45-
45+
4646 /// Used to store the ASWebAuthenticationPresentationContextProvider
4747 private var webAuthenticationPresentationContextProvider : AnyObject ?
48-
48+
4949 public init ( oauth2: OAuth2Base ) {
5050 self . oauth2 = oauth2
5151 }
@@ -137,7 +137,7 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
137137 */
138138 @available ( iOS 11 . 0 , * )
139139 @discardableResult
140- public func authenticationSessionEmbedded( at url: URL , withRedirect redirect: String , prefersEphemeralWebBrowserSession prefersEphemeralWebBrowserSession : Bool = false ) -> Bool {
140+ public func authenticationSessionEmbedded( at url: URL , withRedirect redirect: String , prefersEphemeralWebBrowserSession: Bool = false ) -> Bool {
141141 guard let redirectURL = URL ( string: redirect) else {
142142 oauth2. logger? . warn ( " OAuth2 " , msg: " Unable to parse redirect URL ”(redirect)“ " )
143143 return false
@@ -166,26 +166,21 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
166166 self . authenticationSession = nil
167167 self . webAuthenticationPresentationContextProvider = nil
168168 }
169-
170- #if targetEnvironment(macCatalyst)
169+
170+ #if targetEnvironment(macCatalyst)
171171 authenticationSession = ASWebAuthenticationSession ( url: url, callbackURLScheme: redirectURL. scheme, completionHandler: completionHandler)
172172 return ( authenticationSession as! ASWebAuthenticationSession ) . start ( )
173- #else
174- if #available( iOS 12 , * ) {
175- authenticationSession = ASWebAuthenticationSession ( url: url, callbackURLScheme: redirectURL. scheme, completionHandler: completionHandler)
176- if #available( iOS 13 . 0 , * ) {
177- webAuthenticationPresentationContextProvider = OAuth2ASWebAuthenticationPresentationContextProvider ( authorizer: self )
178- if let session = authenticationSession as? ASWebAuthenticationSession {
179- session. presentationContextProvider = webAuthenticationPresentationContextProvider as! OAuth2ASWebAuthenticationPresentationContextProvider
180- session. prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession
181- }
173+ #else
174+ authenticationSession = ASWebAuthenticationSession ( url: url, callbackURLScheme: redirectURL. scheme, completionHandler: completionHandler)
175+ if #available( iOS 13 . 0 , * ) {
176+ webAuthenticationPresentationContextProvider = OAuth2ASWebAuthenticationPresentationContextProvider ( authorizer: self )
177+ if let session = authenticationSession as? ASWebAuthenticationSession {
178+ session. presentationContextProvider = webAuthenticationPresentationContextProvider as! OAuth2ASWebAuthenticationPresentationContextProvider
179+ session. prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession
182180 }
183- return ( authenticationSession as! ASWebAuthenticationSession ) . start ( )
184- } else {
185- authenticationSession = SFAuthenticationSession ( url: url, callbackURLScheme: redirect, completionHandler: completionHandler)
186- return ( authenticationSession as! SFAuthenticationSession ) . start ( )
187181 }
188- #endif
182+ return ( authenticationSession as! ASWebAuthenticationSession ) . start ( )
183+ #endif
189184 }
190185
191186
@@ -320,23 +315,23 @@ class OAuth2SFViewControllerDelegate: NSObject, SFSafariViewControllerDelegate {
320315
321316@available ( iOS 13 . 0 , * )
322317class OAuth2ASWebAuthenticationPresentationContextProvider : NSObject , ASWebAuthenticationPresentationContextProviding {
323-
318+
324319 private let authorizer : OAuth2Authorizer
325-
320+
326321 init ( authorizer: OAuth2Authorizer ) {
327322 self . authorizer = authorizer
328323 }
329-
324+
330325 public func presentationAnchor( for session: ASWebAuthenticationSession ) -> ASPresentationAnchor {
331- if let context = authorizer. oauth2. authConfig. authorizeContext as? ASPresentationAnchor {
332- return context
333- }
334-
335- if let context = authorizer. oauth2. authConfig. authorizeContext as? UIViewController {
336- return context. view. window!
337- }
338-
339- fatalError ( " Invalid authConfig.authorizeContext, must be an ASPresentationAnchor but is \( String ( describing: authorizer. oauth2. authConfig. authorizeContext) ) " )
326+ if let context = authorizer. oauth2. authConfig. authorizeContext as? ASPresentationAnchor {
327+ return context
328+ }
329+
330+ if let context = authorizer. oauth2. authConfig. authorizeContext as? UIViewController {
331+ return context. view. window!
332+ }
333+
334+ fatalError ( " Invalid authConfig.authorizeContext, must be an ASPresentationAnchor but is \( String ( describing: authorizer. oauth2. authConfig. authorizeContext) ) " )
340335 }
341336}
342337
0 commit comments