amplify-js: Support completing an OAuth flow that is not initiated by Amplify (signInWithRedirect)
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
Angular
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Amplify CLI
Environment information
# Put output below this line
System:
OS: macOS 14.1
CPU: (12) arm64 Apple M3 Pro
Memory: 66.95 MB / 18.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.20.0 - /usr/local/bin/node
npm: 8.19.4 - /usr/local/bin/npm
Browsers:
Chrome: 124.0.6367.119
Safari: 17.1
npmPackages:
aws-amplify: ^6.0.28 => 6.0.28
npmGlobalPackages:
@angular/cli: 16.2.0
@aws-amplify/cli: 12.10.1
corepack: 0.17.0
npm: 8.19.4
Describe the bug
SSO via SAML works for SP-initiated but not for IdP-initiated SSO after upgrading to v6 from v5. I am redirected from the Idp to [https://www.example.com/?code=[Authorization](https://www.example.com/?code=[Authorization) code] but cannot obtain the authentication token. When the getCurrentUser API is executed, a UserUnAuthenticatedException error occurs. IdP-initiated SSO also works in V5. This needs to be resolved immediately if IdP-initiated SSO is to be supported. https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-SAML-session-initiation-idp-initiation.html
Expected behavior
As in V5, the token can be obtained correctly after redirecting from the Idp.
Reproduction steps
- Access Idp’s portal page.
- Select the displayed application.
- Redirect to https://www.example.com?code=[Authorization code].
- UserUnAuthenticatedException error occurs by
getCurrentUser().
Code Snippet
// Put your code below this line.
// Execute `getCurrentUser()` after being redirected from Idp.
await Auth.getCurrentUser();
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 15
- Comments: 33 (12 by maintainers)
Hello everyone. I’ll revisit this issue with the team to discuss its prioritization. Thank you for your patience.
@israx have you got any further with the request to fix/begin supporting IdP logins again in v6? I am relying on this to upgrade from Amplify v5 -> v6.
Cheers.
+1 Cant update to v6 without this
+1 for support please
@israx I have confirmed that it works with the signInWithRedirect API. However, when using IdP-initiated SSO, redirection occurs, making it impossible to use the signInWithRedirect API. What does it mean that IdP-initiated SSO, which was recently supported, cannot be used with Amplify v6? https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-SAML-session-initiation-idp-initiation.html
Hey @bhelabhav thank you for reporting the issue with great details.
Reading the issue description, I suspect that the cause is that the OAuth completion listener was not attached and executed within the JS bundle of the callback URL in your app.
The OAuth listener is a side effect that resides along with the
signInWithRedirectAPI. If the API is not bundled, then the side effect won’t be executed. Could you confirm whether the callback URL in your app actually bundles thesignInWithRedirectAPI? If not, and you can’t include thesignInWithRedirectAPI for any reason, you can import the following module to the bundle used by the callback URL to ensure the OAuth listener is attached so it can complete the OAuth flow:See this doc for more details.
To be noted, your issue is not related to the OP’s request, as your OAuth flow is initiated with the
signInWithRedirect()API within your app.Thanks for following up with the answers to @josefaidt’s questions, @paulcwatts. Anyone else following this issue, feel free to do the same! While there’s no update yet, we are taking note of these use cases to better understand how to support this feature.
I just ran into this as well trying to add IdP-initiated SAML authentication for my amplify v6 app. To answer your questions:
Hey @barakcoh, thanks for adding some additional momentum here. We’re still in the process of reviewing this feature internally and we’ll provide an update here as soon as one is available.
@tllatruw and anyone following this feature request, just wanted to check in. While we don’t have an ETA on when this will be supported, it’s still being reviewed internally by our team. We will provide an update as soon as we can.
I deleted my comment because I think in retrospect it wasn’t related to this specify issue - it seems I had in fact failed to configure my S3 bucket properly for SPA hosting - so apologies for that
supporting IdP logins would be a feature request. The Auth singleton in Amplify v5 has a listener that would capture any
codequery param returned from the social provider and finish the authentication process. Ideally we would need to have a dedicated API that allows to do the same.hello @bbdev9805 . Sorry for any inconvenience using the library. Amplify v6 supports OAuth flows initiated from the same App only. You would need to kick off the OAuth flow by calling the
signInWithRedirectAPI