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

[SAML NewDot] Add SAML flow for web, mweb, desktop #28372

Merged
merged 51 commits into from
Oct 16, 2023

Conversation

NikkiWines
Copy link
Contributor

@NikkiWines NikkiWines commented Sep 28, 2023

Details

Adds support for signing in with SAML on web and mweb.

Fixed Issues

$ #28215
$ #28216
PROPOSAL: N/A Internal

Tests

(Internal)
(for Web, mWeb, desktop)

  1. Follow steps in https://github.com/Expensify/Web-Expensify/pull/38972 to get set up with SAML locally
  2. Configure your account to have SAML enabled but not required in oldDot
  3. Enter the email for your account in newDot
  4. Confirm you see the option to choose to sign in with SAML or with a magic code
  5. Choose the Go Back option and confirm you're dropped back on the sign-in page with your email pre-filled
  6. Press Continue
  7. Choose the Use Magic Code option and confirm you get a magic code sent to your email
  8. Press Go Back and confirm you're back on the sign-in page with your email pre-filled
  9. Press Continue
  10. Choose Use Single Sign On option
  11. Confirm you briefly see an interstitial page about launching your SSO provider's login portal
  12. (web/mweb only) Navigate back to the root page (i.e. localhost:8082/ or new.expensify.com)
  13. (web/mweb only) Confirm you land on the page with the option to choose to sign in with SAML or with a magic code
  14. (web/mweb only) Choose Use Single Sign On option
  15. Enter your SSO credentials
  16. Confirm you're redirected back to New Expensify and are logged into your account
  17. In oldDot, set SAML to required
  18. In a new incognito window, open New Expensify and enter your email address
  19. Confirm you're automatically redirected to your SSO providers login page (with the interstitial page being briefly shown)
  20. (web/mweb only) Navigate back to the root page (i.e. localhost:8082/ or new.expensify.com)
  21. (web/mweb only) Confirm you land on the sign-in page without your login prefilled
  22. (web/mweb only) Enter the email for a non-SAML account and confirm you're directed to the magic code view for that login
  23. (web/mweb only) Click go back and enter your SAML required login once again.
  24. (web/mweb only) Confirm you're automatically redirected to your SSO providers login page
  25. Enter your credentials and confirm you're successfully logged into New Expensify

(for ios/android)

  1. Log into the same account you used in step 17 above
  2. Confirm you see an error showing that you cannot log into an account with SAML required

(External)
(for Web, mWeb, Desktop)

  1. Create an account with a validated domain on expensify.com
  2. Configure your account to have SAML enabled but not required
  3. Enter the email for your account in New Expensify
  4. Confirm you see the option to choose to sign in with SAML or with a magic code
  5. Choose the Go Back option and confirm you're dropped back on the sign-in page with your email pre-filled
  6. Press Continue
  7. Choose the Use Magic Code option and confirm you get a magic code sent to your email
  8. Press Go Back and confirm you're back on the sign-in page with your email pre-filled
  9. Press Continue
  10. Choose Use Single Sign On option
  11. Confirm you briefly see an interstitial page about launching your SSO provider's login portal
  12. (web/mweb only) Navigate back to the root page (i.e. localhost:8082/ or new.expensify.com)
  13. (web/mweb only) Confirm you land on the page with the option to choose to sign in with SAML or with a magic code
  14. (web/mweb only) Choose Use Single Sign On option
  15. In expensify.com, set SAML to required
  16. In a new incognito window, open New Expensify and enter your email address
  17. Confirm you're automatically redirected to your SSO providers login page (with the interstitial page being briefly shown)
  18. (web/mweb only) Navigate back to the root page (i.e. localhost:8082/ or new.expensify.com)
  19. (web/mweb only) Confirm you land on the sign-in page without your login prefilled
  20. (web/mweb only) Enter the email for a non-SAML account and confirm you're directed to the magic code view for that login
  21. (web/mweb only) Click go back and enter your SAML required login once again.
  22. (web/mweb only) Confirm you're automatically redirected to your SSO providers login page

(for ios/android)

  1. Log into the same account you used in step 16 above
  2. Confirm you see an error showing that you cannot log into an account with SAML required

Offline tests

  1. Navigate to the login page for New Expensify and enter your email
  2. Confirm you see the
  3. Disable your wifi or disable your network connections
  4. Confirm you see the offline indicator
Screenshot 2023-09-28 at 15 47 43

QA Steps

Same as test steps

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover 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 tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (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 not onIconClick)
    • 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
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • 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
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • 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
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • 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 that Avatar 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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • 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 the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

SAML Required Flow

web-required.mov

SAML Enabled Flow

web-enabled.mov
Mobile Web - Chrome

SAML Required Flow

SAML Enabled Flow

Simulator.Screen.Recording.-.iPhone.14.-.2023-09-28.at.17.01.20.mp4
Mobile Web - Safari

SAML Required Flow

mweb-required.mp4

SAML Enabled Flow

mweb-enabled.mp4
Desktop

SAML Required Flow

desktop-required.mov

SAML Enabled Flow

desktop-enabled.mov
iOS

SAML Required Flow

Simulator.Screen.Recording.-.iPhone.14.-.2023-10-12.at.18.36.53.mp4

(SAML Enabled is the same as the current magic code flow)

Android

SAML Required Flow

(SAML Enabled is the same as the current magic code flow)

@NikkiWines NikkiWines requested a review from a team as a code owner September 28, 2023 07:46
@NikkiWines NikkiWines self-assigned this Sep 28, 2023
@melvin-bot melvin-bot bot requested review from situchan and removed request for a team September 28, 2023 07:46
@melvin-bot
Copy link

melvin-bot bot commented Sep 28, 2023

@situchan @ 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]

src/languages/en.ts Outdated Show resolved Hide resolved
src/languages/en.ts Outdated Show resolved Hide resolved
src/pages/signin/SignInPage.js Outdated Show resolved Hide resolved
src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js Outdated Show resolved Hide resolved
src/pages/signin/SAMLEnabledForm.js Outdated Show resolved Hide resolved
src/languages/es.ts Outdated Show resolved Hide resolved
src/pages/signin/SignInPage.js Outdated Show resolved Hide resolved
src/pages/signin/SignInPage.js Outdated Show resolved Hide resolved
@situchan
Copy link
Contributor

Lint is failing

Is it ready for external review or wait until https://github.com/Expensify/Web-Expensify/pull/38972 is deployed?

@MonilBhavsar
Copy link
Contributor

I think this should be on HOLD until Web-E PR is deployed. But yes, It can be reviewed

@NikkiWines
Copy link
Contributor Author

NikkiWines commented Sep 28, 2023

@situchan you can review the portions under the (external) section in the Tests for now but the actual redirect to the SAML provider and then back to New Expensify won't work until the internal PR is deployed to prod

@NikkiWines NikkiWines changed the title [SAML NewDot] Add SAML flow for web and mweb [HOLD][SAML NewDot] Add SAML flow for web and mweb Sep 28, 2023
src/languages/en.ts Outdated Show resolved Hide resolved
src/languages/es.ts Outdated Show resolved Hide resolved
src/pages/signin/SAMLEnabledForm.js Outdated Show resolved Hide resolved
src/pages/signin/SAMLEnabledForm.js Outdated Show resolved Hide resolved
src/pages/signin/SAMLSignInPage/index.js Outdated Show resolved Hide resolved
src/pages/signin/SAMLSignInPage/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@situchan situchan left a comment

Choose a reason for hiding this comment

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

Am I missing any config? I am trying to follow External step but I am not able to reach SAML page on web. I enabled permission in Permissions.ts

Screen.Recording.2023-10-02.at.7.48.12.AM.mov


function SAMLSignInPage(props) {
useEffect(() => {
window.open(`${CONFIG.EXPENSIFY.SAML_URL}?email=${props.credentials.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}`, '_self');
Copy link
Contributor

@situchan situchan Oct 2, 2023

Choose a reason for hiding this comment

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

It's possible that this page can be accessed on native when newDotSAML beta enabled and window.open will crash.

// SAML is temporarily restricted to users on the beta or to users signing in on web and mweb
if (Permissions.canUseSAML() || platform === CONST.PLATFORM.WEB) {
shouldShowSAMLEnabledForm = hasAccount && hasLogin && isSAMLEnabled && !isSAMLRequired && isUsingSAMLLogin;
shouldInitiateSAMLLogin = hasAccount && hasLogin && isSAMLRequired;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 why would it crash? credentials.login is the only portion we'd need to be defined and we'll only show the SAMLEnabledForm (now ChooseSSOOrMagicCode) or intiaite the SAML login (i.e. navigate to that URL immediately) if the login is set.

@NikkiWines
Copy link
Contributor Author

Updated once more!

@situchan
Copy link
Contributor

Code looks good. (lint failing)

I started testing with private domain email.

Configure your account to have SAML enabled but not required

Where can I enable this?

@NikkiWines
Copy link
Contributor Author

Where can I enable this?

In expensify.com under Settings > Domains > [Your Domain] > SAML

@situchan
Copy link
Contributor

Where can I enable this?

In expensify.com under Settings > Domains > [Your Domain] > SAML

I don't find Domains in Settings. Can you please share that url?

Copy link
Contributor

@MonilBhavsar MonilBhavsar left a comment

Choose a reason for hiding this comment

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

This is open since long. So going to merge this now.
There is an issue with transitioning which will hopefully be fixed by #28984. If not, we can address it in a separate PR

@MonilBhavsar MonilBhavsar merged commit febc3cf into main Oct 16, 2023
12 checks passed
@MonilBhavsar MonilBhavsar deleted the nikki-saml-newdot-web branch October 16, 2023 15:54
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@kavimuru
Copy link

@NikkiWines @MonilBhavsar Are QA steps internal?

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.85-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@NikkiWines
Copy link
Contributor Author

@kavimuru since qa@expensifail.com has a OneLogin account set up this doesn't need to be internally tested! However, if the please revert the expensifail.com domain to "SAML enabled" once testing is done 🙇

@NikkiWines
Copy link
Contributor Author

I'll also do some testing on staging just to try things out

@NikkiWines
Copy link
Contributor Author

The redirect back to NewExpensify isn't working for me on staging, but I think it might be that we need to test this on prod 🤔 looking at the logs now

@NikkiWines
Copy link
Contributor Author

NikkiWines commented Oct 17, 2023

Going to hide these changes behind a beta so we can test on prod without it causing issues for customers - #29798

@sakluger
Copy link
Contributor

I commented on the beta PR, but I don't think a beta is necessary. Ideally we can test this in a day or so, and I can't think of many downsides to having it accessible to real customers. Worst case, they run into errors and we fix the bug.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.3.85-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.86-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.3.86-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

)(LogInWithShortLivedAuthTokenPage);
export default withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
session: {key: ONYXKEYS.SESSION},
Copy link
Contributor

Choose a reason for hiding this comment

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

The session prop appears unused. Do you know if it's needed here?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove it most probably. Seems like we removed the usage, but forgot to remove this key here. /cc @NikkiWines to be double sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, we can remove this 👍 I can do that as part of #29526 unless you'd like to make a separate PR fro it @roryabraham

Copy link
Contributor

Choose a reason for hiding this comment

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

@NikkiWines if you want to do it as part of #29526 that would be great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

const {translate} = useLocalize();

useEffect(() => {
window.open(`${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}`, '_self');
Copy link
Contributor

Choose a reason for hiding this comment

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

window.open broke route history and user couldn't go back from SAML page. ref: #29825

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.

8 participants