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

fix(auth): Allow Web Urls on signInWithRedirect in Mobile Apps #12969

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

elorzafe
Copy link
Contributor

@elorzafe elorzafe commented Feb 7, 2024

Description of changes

Adds fallback URL in case customer wants to redirect native app to a website

Issue #, if available

fixes: #12890

Description of how you validated changes

React-Native CLI App

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@elorzafe elorzafe requested a review from a team as a code owner February 7, 2024 00:25
throw invalidRedirectException;
} else {
// fallsback to available URL https://github.com/aws-amplify/amplify-js/issues/12890
return redirects[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always return the first url? What if they want to call a particular url instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how a customer would select that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By re-directing to the right url is understanding please correct me
if and only if I am wrong or not
@elorzafe 😕

// fallsback to available URL https://github.com/aws-amplify/amplify-js/issues/12890
return redirects[0];
}
}
return redirect;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes will still return the mobile url right?
Ex: Giving ["mobile://", "http://"] as input the output is still "mobile://" url
In the issue linked, it seems like they want to hit "http://" first then "mobile://"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, the issue is how a customer would choose which url to choose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still choose first mobile url because is filtered. Now if you want to force the web url, that seems something that could be address by an API change

Copy link
Contributor

@jimblanc jimblanc Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, with the current API there's no way to actively select which URL gets used. We (along with other platforms) use a heuristic to determine which URL to use.

Copy link
Contributor

@jimblanc jimblanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically makes sense to me. Working on testing the change now and will hold approval until then. One small nit.

@@ -10,7 +10,12 @@ export function getRedirectUrl(redirects: string[]): string {
!redirect.startsWith('http://') && !redirect.startsWith('https://')
);
if (!redirect) {
throw invalidRedirectException;
}
if (redirects.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Looks like a tabbing error with this block

// fallsback to available URL https://github.com/aws-amplify/amplify-js/issues/12890
return redirects[0];
}
}
return redirect;
Copy link
Contributor

@jimblanc jimblanc Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, with the current API there's no way to actively select which URL gets used. We (along with other platforms) use a heuristic to determine which URL to use.

Copy link
Contributor

@jimblanc jimblanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovered some open items while testing, blocking PR

@borgoat
Copy link

borgoat commented Feb 16, 2024

I just realised: this fixes #12890 but ignores #12956 - which was closed in favour of the former. While the 2 issues have a similar cause, they're not equal. In my case I have a Capacitor (not RN) app - which behaves entirely like a web app - which has to redirect to a native app. So it's more like the other way around - and the misbehaving implementation is packages/auth/src/providers/cognito/utils/oauth/getRedirectUrl.ts

Can this be addressed here too? Or should I open another PR on top?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to use https redirectSignOutUrls when using amplify v6
5 participants