Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The external login UI is not working when closing the dialog programmatically #3896

Closed
medhatIbsais-Harri opened this issue Oct 9, 2024 · 12 comments
Labels
auth Issues related to the Auth category question General question

Comments

@medhatIbsais-Harri
Copy link

medhatIbsais-Harri commented Oct 9, 2024

Describe the bug

The external login dialog is not appearing again when dismissing it programmatically, the idea that we have an app the at some states we changes the root view controller, if the user prompted the external login UI and the root view changed, if the user tried again to prompt the external login dialog, it will get stuck and the dialog will not appear again,
we have two apps, the first one uses Amplify and the other one uses AWSMobileClient, it works normally on the who that uses AWSMobileClient, but its not working on Amplify, check the screen recording on Drive please
Screen recordings

you can use the code below for example to dismiss the presented view controller

 // check if there is any presented view
 if let presentedViewController = UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.rootViewController?.presentedViewController {
                
  // dismiss
 presentedViewController.dismiss(animated: false, completion: nil)
 }

Steps To Reproduce

Steps to reproduce the behavior:
1. Type the external login company URL
2. When the external login dialog appears, change the root controller or simply dismiss the presented view controller like the code added in the description 
3. Try to prompt the dialog again 
4. It will not appear

Expected behavior

it should work normally and show the dialog

Amplify Framework Version

1.31.0

Amplify Categories

Auth

Dependency manager

Cocoapods

Swift version

5.0

CLI version

Not installed

Xcode version

15.4

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

17.4

Device

iPad mini 6th generation

Specific to simulators

No response

Additional context

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Oct 9, 2024
@harsh62
Copy link
Member

harsh62 commented Oct 9, 2024

@medhatIbsais-Harri Would you be able to share more context on the code that is being used? That is more code snippets around how your login UI is using Amplify

@harsh62 harsh62 added auth Issues related to the Auth category question General question labels Oct 9, 2024
@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 9, 2024
@medhatIbsais-Harri
Copy link
Author

Hello @harsh62, yes sure, check the code below please, also just an important note, that after dismissing the external login view programmatically, anything related to amplify will hang even the sign out Amplify.Auth.signOut,

simply just add the code below and start a timer for example to dismiss the presented view "as the code in description" after 10 seconds, then everything related Amplify will hang.

let hostedUIOptions = AuthSocialWebUISignInOperation.Request.Options(scopes: ["profile","openid", "email"], signInQueryParameters: nil, signOutQueryParameters: nil, tokenQueryParameters: nil, pluginOptions: AWSAuthWebUISignInOptions(preferPrivateSession: true))
        
Amplify.Auth.signInWithWebUI(for:  AuthProvider.custom(source.name), presentationAnchor: UIApplication.shared.windows.filter({$0.isKeyWindow}).first!, options: hostedUIOptions, listener: { result in
.......
})

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 10, 2024
@harsh62
Copy link
Member

harsh62 commented Oct 10, 2024

@medhatIbsais-Harri Could you try not passing the presentation anchor and let the library create its own. So something like:

Amplify.Auth.signInWithWebUI(for:  AuthProvider.custom(source.name), options: hostedUIOptions, listener: { result in
.......
})

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 10, 2024
@medhatIbsais-Harri
Copy link
Author

Hello @harsh62, is the above code working with you?, because the presentation anchor is a required parameter

Screenshot 2024-10-11 at 10 29 06 AM

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 11, 2024
@medhatIbsais-Harri
Copy link
Author

medhatIbsais-Harri commented Oct 11, 2024

Hello @harsh62, can you please try the case I sent you, its very easy to reproduce, just add the below code, then after its being dismissed try to call Amplify.Auth.signInWithWebUI again it will never open the dialog, also even if you tried to call anything related to Amplify it will not work even the Amplify.Auth.signOut

let hostedUIOptions = AuthSocialWebUISignInOperation.Request.Options(scopes: ["profile","openid", "email"], signInQueryParameters: nil, signOutQueryParameters: nil, tokenQueryParameters: nil, pluginOptions: AWSAuthWebUISignInOptions(preferPrivateSession: true))
        
Amplify.Auth.signInWithWebUI(for:  AuthProvider.custom(source.name), presentationAnchor: UIApplication.shared.windows.filter({$0.isKeyWindow}).first!, options: hostedUIOptions, listener: { result in
.......
})

Timer.scheduledTimer(withTimeInterval: 15, repeats: false) { _ in
            
      if let presentedViewController = UIApplication.shared.windows.first(where: { $0.isKeyWindow})?.rootViewController?.presentedViewController {

       presentedViewController.dismiss(animated: false, completion: nil)
           }
  }


@harsh62
Copy link
Member

harsh62 commented Oct 15, 2024

This is because you are forcefully dismissing the view controller in the following code snippet.

Timer.scheduledTimer(withTimeInterval: 15, repeats: false) { _ in        
      if let presentedViewController = UIApplication.shared.windows.first(where: { $0.isKeyWindow})?.rootViewController?.presentedViewController {
       presentedViewController.dismiss(animated: false, completion: nil)
    }
  }

Amplify signInWithWebUI is listening for callbacks from ASWebAuthentication and in this case the callback is not triggered. Because the callback is not triggered, Amplify is still waiting and discarding any other requests that come in.
We have a state machine running that currently in waiting for sign in state. I would suggest that you rely on the users either completing the flow or cancelling the flow, which would call the correct callbacks and will not cause any problems.


Also could you try passing nil value to the presentation anchor for your original issue, if nil value is received, Amplify would create its own presentation anchor.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 15, 2024
@medhatIbsais-Harri
Copy link
Author

Hello @harsh62, for passing nil it will not work, because the presentation anchor is not an optional parameter, whatever regarding the dismiss issue, can't you override the Apple dismiss method and call the cancel call back in it?
because the above issue is only happening on Amplify side, its working well with AWSMobileClient

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 15, 2024
@harsh62
Copy link
Member

harsh62 commented Oct 15, 2024

@medhatIbsais-Harri I just saw now that you are using Amplify V1 (1.31.0). Can you migrate to Amplify V2 as Amplify V1 has been deprecated?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 15, 2024
@medhatIbsais-Harri
Copy link
Author

Hello @harsh62, yes we have the plan to release our apps with Amplify v2, but for the current issue its also happens on lower version of Amplify, and what is the cause that its working normally on AWSMobileClient?

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 15, 2024
@harsh62
Copy link
Member

harsh62 commented Oct 15, 2024

but for the current issue its also happens on lower version of Amplify, and what is the cause that its working normally on AWSMobileClient

Amplify V1 wraps some of its own logic on top of AWSMobileClient, there could be a bug or unhandled code paths in the implementation which is causing this issue.

For now, I would suggest trying out Amplify V2 with and without presentation anchor. If this issue still persists in Amplify V2, then please let us know and we will investigate further.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Oct 15, 2024
@medhatIbsais-Harri
Copy link
Author

@harsh62 ok thank you

@github-actions github-actions bot removed the pending-triage Issue is pending triage label Oct 16, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth category question General question
Projects
None yet
Development

No branches or pull requests

2 participants