Skip to content

Commit 68748bf

Browse files
authored
Fix: ASPresentationAnchor or UIViewController for authorize context (p2#361)
1 parent 3e5852e commit 68748bf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/iOS/OAuth2Authorizer+iOS.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,15 @@ class OAuth2ASWebAuthenticationPresentationContextProvider: NSObject, ASWebAuthe
328328
}
329329

330330
public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
331-
guard let context = authorizer.oauth2.authConfig.authorizeContext as? UIViewController else {
332-
fatalError("Invalid authConfig.authorizeContext, must be a UIViewController but is \(String(describing: authorizer.oauth2.authConfig.authorizeContext))")
333-
}
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+
}
334338

335-
return context.view.window!
339+
fatalError("Invalid authConfig.authorizeContext, must be an ASPresentationAnchor but is \(String(describing: authorizer.oauth2.authConfig.authorizeContext))")
336340
}
337341
}
338342

0 commit comments

Comments
 (0)