-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 automatic authentication with magic link. #19637
Conversation
@NikkiWines @parasharrajat One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Co-authored-by: Rajat Parashar <parasharrajat@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion that'll cause a bunch of changes
src/libs/actions/Session/index.js
Outdated
if (twoFactorAuthCode) { | ||
params.twoFactorAuthCode = twoFactorAuthCode; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we're explicitly passing null
for the twoFactorAuthCode
in several places (but that we often pass a preferredLocale
, which is the param after it).
Maybe a cleaner solution would be to update this function (and also signInWithValidateCodeAndNavigate
which calls this) so that twoFactorAuthCode
is the last param and defaults to ''
. Then we don't even need this if
It's more changes but ultimately I think it's better than passing null
in a bunch of places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristipaval Are you going to make this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on them atm
src/libs/actions/Session/index.js
Outdated
// Pass twoFactorAuthCode to server only if it has a valid value, otherwise php might convert it to "null" as a string. | ||
if (twoFactorAuthCode) { | ||
params.twoFactorAuthCode = twoFactorAuthCode; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a sign that this is an internal bug? Let's add the filter logic in php, if the twoFactorAuthCode is empty/unset, ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should have better validation/sanitization on backend @cristipaval.
@cristipaval Are we going make requested changes in the PR? |
on it! I like Nikki's suggestion |
Ready for a new round, @parasharrajat @NikkiWines @s77rt |
@cristipaval because we refactored a few parts in this PR, can you please extend the QA steps to cover those components/pages as well? Also, it will be a great help to me if you can tell me what pages are affected by these refactors other than then main login page/validation page. |
I don't believe any other pages are impacted, since this logic is only used for signing into the app but maybe @cristipaval knows better than I do here. We will need to be sure to test signing in on all platforms on accounts with 2FA enabled and without 2FA enabled. Also, we'll need to test manually entering the magic code and also logging in by clicking on the magic link. |
Thanks for that help. Starting testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Screenshots🔲 iOS / nativeScreen.Recording.2023-05-27.at.1.37.17.AM.mov🔲 iOS / SafariScreen.Recording.2023-05-27.at.2.01.52.AM.mov🔲 MacOS / Desktop🔲 MacOS / ChromeScreen.Recording.2023-05-27.at.2.03.34.AM.mov🔲 Android / ChromeScreen.Recording.2023-05-27.at.2.31.55.AM.mov🔲 Android / nativeScreen.Recording.2023-05-27.at.2.28.38.AM.mov |
I saw one issue, Where I am unable to go back from 2fa screen. This might be related to this issue. But it is one. Steps:
Screen.Recording.2023-05-27.at.1.40.35.AM.movEven if the page is refreshed/reopened, if I put real 2fa code, It logs me in. |
I am receiving incorrect 2FA code with following steps even if the 2fa is correct.
Screen.Recording.2023-05-27.at.1.44.45.AM.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the above reported funky bugs, it's working. I am expecting those are unrelated and will be follow-up. let me know if I am wrong.
Reviewer Checklist
- I have verified the author checklist is complete (all boxes are checked off).
- I verified the correct issue is linked in the
### Fixed Issues
section above - I verified testing steps are clear and they cover the changes made in this PR
- I verified the steps for local testing are in the
Tests
section - I verified the steps for Staging and/or Production testing are in the
QA steps
section - I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
- I verified the steps for local testing are in the
- I checked that screenshots or videos are included for tests on all platforms
- I included screenshots or videos for tests on all platforms
- I verified tests pass on all platforms & I tested again on:
- Android / native
- Android / Chrome
- iOS / native
- iOS / Safari
- MacOS / Chrome / Safari
- MacOS / Desktop
- If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
- I verified proper code patterns were followed (see Reviewing the code)
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
toggleReport
and notonIconClick
). - I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g.
myBool && <MyComponent />
. - I verified that comments were added to code that is not self explanatory
- I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
- I verified any copy / text shown in the product is localized by adding it to
src/languages/*
files and using the translation method - I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the
Waiting for Copy
label for a copy review on the original GH to get the correct copy. - I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
- I verified the JSDocs style guidelines (in
STYLE.md
) were followed
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
- If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- I verified that this PR follows the guidelines as stated in the Review Guidelines
- I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like
Avatar
, I verified the components usingAvatar
have been tested & I retested again) - I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
- If a new component is created I verified that:
- A similar component doesn't exist in the codebase
- All props are defined accurately and each prop has a
/** comment above it */
- The file is named correctly
- The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- The only data being stored in the state is data necessary for rendering and nothing else
- For Class Components, any internal methods passed to components event handlers are bound to
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor) - Any internal methods bound to
this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
) - All JSX used for rendering exists in the render method
- The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
- If any new file was added I verified that:
- The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
- If a new CSS style is added I verified that:
- A similar style doesn't already exist
- The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)
- If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
- If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avatar
is modified, I verified thatAvatar
is working as expected in all cases) - If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
- If a new page is added, I verified it's using the
ScrollView
component to make it scrollable when more elements are added to the page. - If the
main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps. - I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
cc: @NikkiWines
🎀 👀 🎀 C+ reviewed
One more Bug: Opening magic on the browser where you haven't started login(haven't entered the email), asks you for a password. Steps:
|
I approved as the main issue is solved in this PR and in case we want to look into these issues in separate issues. |
How do we open the magic link on desktop app in dev? |
At 0.40 seconds you refreshed the page, but instead, you have to go back to the login page and then open the magic link in a new tab. in my video, it is 0.41-0.43 sec. |
For not being able to go back to the magic code view from the 2FA code view I think this is intentional since to get to the 2FA view you will have had to "use up" a correct magic code. Going back to that view wouldn't make sense. If we do decide that's a bug, I think it should be separate from this issue.
I don't believe we have a flow for that, as it added a lot of complexity. There is no "automatic" authentication for desktop |
I could've sworn I didn't refresh anything but it does look like that from the video 😅 I'll retest once more |
Ok, I was able to reproduce the issue from here. It seems like in this case we don't end up passing the validateCode anymore so we seem to be throwing in the backend because we're not passing a password or validateCode, only the 2FA code |
Rescinding my approval since we should probably fix that issue to ensure we're passing the magic code and 2FA when applicable |
It looks like I can't reproduce your issue @parasharrajat Screen.Recording.2023-05-29.at.23.23.10.mov |
@cristipaval I also explained the reproduction in the above discussion. Does that help? There is also a video for it #19637 (comment)? |
Could you please look at my screen recording? I think I am doing the exact same steps 🤷 |
You are not doing the exact same steps. Instead of pasting the link you navigated away by changing the URL at 0.24 secs. |
@parasharrajat it doesn't seem like i'm able to reproduce this anymore. Can you try once again? screencap.movSince this is a more niche flow involving going back on the login flow, maybe we can make a separate issue once this is consistently reproducible. It would be good to get this PR out since we know the main flow is broken |
Back to work. Retesting. |
I am stuck in this loop. How can I reset it? Screen.Recording.2023-06-01.at.12.12.50.AM.mov |
@parasharrajat if entering the authenticator code doesn't log you in, you can try opening the JSContext for the simulator in safari and deleting onyxDB and clearing your cache. |
Let me do that. |
Ok, so I cleared the data and tried again and I can still reproduce this issue. |
I still think we should possibly handle that as a separate issue. The majority of users aren't going to be going through a flow on mWeb where they manually paste the link over the original tab where they began signing in. It's definitely a bug, but a much less severe one than the main link not working at all on mobile devices when the user has 2FA enabled. We should definitely fix it, but I think it's best to patch the more severe bug first, then handle the smaller bugs (the one you've identified and also that bug where you get caught in the login <-> 2FA code loop) separately |
That's why I also approved the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, @parasharrajat do you want to post that bug in #expensify-bugs since you found it in this PR? If not, I can spin up a new issue for it today |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/NikkiWines in version: 1.3.22-0 🚀
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.22-1 🚀
|
2 similar comments
🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.22-1 🚀
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.22-1 🚀
|
Details
Fixes the automatic authentication with magic links on accounts with 2fa enabled.
Fixed Issues
$ #19636
Tests
Note: Automatic authentication with the magic link is disabled for the desktop App.
Offline tests
N/A
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
web.mov
Mobile Web - Chrome
mobile.chrome.mov
Mobile Web - Safari
mobile.safari.mov
Desktop
N/AiOS
Screen.Recording.2023-05-26.at.02.01.41.mov
Android
Screen.Recording.2023-05-26.at.02.08.54.mov