ThexXTURBOXx / flutter_web_auth_2

Flutter plugin for authenticating a user with a web service
https://pub.dev/packages/flutter_web_auth_2
MIT License
53 stars 53 forks source link

[Bug]: iOS BaseWebAuth not performing #140

Open prooshani opened 2 hours ago

prooshani commented 2 hours ago

Description

First, Thank you for this useful package.

I am using this package and found that, while in Android version everything looks and works fine, in iOS it will somehow bypass "authenticate" function and ask for user credentials even if the user is logged in and has valid token in OAuth2 server.

In Android version, if the user is logged in it will return token and redirect automatically to the callback url while in iOS everything looks the same as android but "authenticate" function terminates on call. Without exception it just terminate the function and return null.

Also, in swiftFlutterWebAuth2plugin lines 77 , 79 has problem with "callback" on compile and after changing to this: _session = ASWebAuthenticationSession(url: url, callbackURLScheme: callbackURLScheme, completionHandler: completionHandler!) the problem will gone.

Is there anything specific regarding iOS version that I missed?

Thanks for any help in advance

Minimal Reproduction

Exception or Error

No exception, it just terminate. Example will send abort to the application in xCode

Expected Behaviour

If the user is logged in the authenticate should return callback url with valid token from OAuth server.

Screenshots

No response

Additional context

No response

Device

iPhone 15 pro

OS

ios 17.5.1

Browser

embed

Flutter version

3.24.3

flutter_web_auth_2 version

4.0.1

Checklist

ThexXTURBOXx commented 2 hours ago

Is there anything specific regarding iOS version that I missed?

See: https://github.com/ThexXTURBOXx/flutter_web_auth_2?tab=readme-ov-file#upgrading-to-4x (in particular, now iOS 17.4 and macOS 14.4 are required) Thanks to Apple, there is no way to use the preprocessor to decide whether the new function is indeed available. This is a fatal design flaw, but Apple sadly does not care enough to handle this problem.

prooshani commented 2 hours ago

Is there anything specific regarding iOS version that I missed?

See: https://github.com/ThexXTURBOXx/flutter_web_auth_2?tab=readme-ov-file#upgrading-to-4x (in particular, now iOS 17.4 and macOS 14.4 are required) Thanks to Apple, there is no way to use the preprocessor to decide whether the new function is indeed available. This is a fatal design flaw, but Apple sadly does not care enough to handle this problem.

Thanks for the quick answer. I am already using 17.4+ os so this is not the problem. This is there in a very same situation with this package even from version 3.1.2. The boundaries made by new iOS is understandable but, we have this issue for a long time (+6 month+). I feel I have missed something in declarations specific to iOS because the Android version works really well... This is so unbelievable that, I have reached to a point that I know exactly where my application fails but I cannot resolve it.

ThexXTURBOXx commented 1 hour ago

Version 3.1.2 works correctly as it has tested heavily. From version 4.x on, 17.4 is required. Please note that this does not necessarily mean that OS version must be greater than 17.4. Your compile SDK version must be at least 17.4 (supported from Xcode 15.3 on). That has also been tested heavily and hence I am very positive that it works correctly.

prooshani commented 1 hour ago

Version 3.1.2 works correctly as it has tested heavily. From version 4.x on, 17.4 is required. Please note that this does not necessarily mean that OS version must be greater than 17.4. Your compile SDK version must be at least 17.4 (supported from Xcode 15.3 on). That has also been tested heavily and hence I am very positive that it works correctly.

So you mean I have to set my sdk platform to ios 17.4? like before which it was ios 11? The funny part is that in version 3.1.2 it is demanded to set ios platform too 11 which is not possible anymore in new version of XCode. it would be 12 at least.

If I use version 3.1.2 the platform will be ios 12 -> not working correctly on ios If I use version 4.0.1 the platform should be 17.4 -> Not possible! the end-users will narrow down to very few.

Is it possible to use version 3.1.2 with ios platform 12 with some tweaks?

ThexXTURBOXx commented 57 minutes ago

Yes, you need to set your SDK platform to 17.4. It should have never been just 11 from flutter_web_auth_2's side of things - I have seen deployed apps which use newer SDK platform versions and the code compiles and works just fine.

You should continue to be able to use version 3.1.2 with any iOS version (since the old constructor for ASWebAuthenticationSession is only deprecated, but not yet removed: https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/init(url:callbackurlscheme:completionhandler:)). However, 3.x will not receive the same support treatment as 4.x from my side.