p2 / OAuth2

OAuth2 framework for macOS and iOS, written in Swift.
Other
1.14k stars 275 forks source link

authConfig.authorizeContext will not accept a UIWindow #391

Closed pepas-everly closed 5 months ago

pepas-everly commented 2 years ago

I ran into an unexpected problem: authConfig.authorizeContext will not accept a UIWindow, and instead must be a UIViewController.

This is the implementation of presentationAnchor:

    public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        guard let context = authorizer.oauth2.authConfig.authorizeContext as? UIViewController else {
            fatalError("Invalid authConfig.authorizeContext, must be a UIViewController but is \(String(describing: authorizer.oauth2.authConfig.authorizeContext))")
        }

        return context.view.window!
    }

However, if we look at the definition of ASPresentationAnchor:

public typealias ASPresentationAnchor = UIWindow

it is in fact a UIWindow.

The implementation of presentationAnchor is befuddling:

This is a bit contrived. Why not just accept a UIWindow via authConfig.authorizeContext in the first place?

ossus-lib commented 5 months ago

This now accepts either.