MaikuB/flutter_appauth

iOS - response is not restored on the current auth session when using Universal Link

sachinexec opened this issue ยท 5 comments

Current Behaviour:
When started the auth process using the method authorizeAndExchangeCode, I see a popup in-app browser. After filling in the user credentials, it authenticates and asks me to authorize, once I clicked on Approve to authorize, then nothing happens. The popup remains open.

What I already did?
I have set up the Universal Link in iOS and already verified that my Universal Link is set up properly.

Moreover, after clicking on the Approve button to authorize, I am able to capture the redirect URL from userActivity NSUserActivity in the AppDelegate. Printed the URL and verified that it contained the code and state as query parameters.

Also tested using a custom scheme like my.domain.name://auth-callback, and it works just fine. But that is not an option available to me as I am using the Google Identity Platform with Firebase Auth. When registering my auth provider on the Google Identity Platform, it generated the redirect URL by itself and is not editable. The redirect URL starts with https:// and so I am bound to use Universal Link in iOS and App Link in Android. On Android, it is working fine after setting up the App Link.

As the Universal Link is set up correctly (as I am able to capture redirect URL in the AppDelegate) and also verified that the auth is working fine with the custom scheme that means the only possible issue here is the response (redirect URL) is not able to restore on the current auth session when using Universal Link.

Please help, I am stuck on this issue for 4-5 days.

MaikuB commented

Not able to help you with this as I wrote this library as a wrapper to native SDKs maintained by others. This means I don't the full ins and outs of it and will not necessarily get to use all the various features on apps I work on. When I initially published this, it wasn't even for an app that needed it even, rather I saw that there was a need for this so published it so others can make use and help contribute to it. If you need help on this then you'll need to ask online in communities like Slack, Stack Overflow etc to see if anyone can help. There may be those on the GitHub repos for AppAuth iOS who have posted how they got it to work in the scenario like yours as well

I was facing the same issue as you and fixed that. I found a solution by adding an extra step for the redirect mechanism inside the native implementation. I created a fork and overridden that inside my flutter project.

Great, thanks for sharing.
I used the AppAuth-iOS package in Swift for the iOS platform as I was unable to make it work with Flutter. The Flutter package flutter_appauth is still there for the Android platform. Then in AppDelegate, listened for the universal link and resumed the auth flow with that universal link. This worked for me.

@kamilzajacdeviniti how do you used your fork? I see your redirect fix foiund its way into AppAuth-iOS but they did not release it yet.

@sachinexec what did you do in the AppDelegate to fix the problem?

@anton-brass everything you need to do is to override the entry inside the Podfile (inside iOS folder) like that:

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  pod 'AppAuth', :git => 'https://github.com/kamilzajacdeviniti/AppAuth-iOS.git', :commit => 'ee9d0ec6fa368a1179e9382afc0153085bef4e28'

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end