-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from all commits
7f9875e
b7f9376
0551e55
a4b6622
e619191
66a46b4
75e4482
31222f1
f99cf33
f144da8
0c74b4a
464f2dd
bf8f5d4
4b08ced
4308871
3813e1a
e66d4d7
6c8e9cc
5f82eb1
a3ab496
4ba9b0d
960bda8
a4dd935
9c34b6b
a11f6f6
e3ffff9
12bf1cc
49c03d1
eb8468b
2a86c47
ef1d7f9
292fa79
44ecdaa
887960c
a5c1152
26585bc
5a27e2b
894b588
a96f0b1
12c291b
d19ce5b
0c67e94
062fb6b
df377f2
371372c
23aaee1
a6b7b6b
4447dc2
f6c0d58
d7982fa
b793275
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'underscore'; | ||
import styles from '../../styles/styles'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import Text from '../../components/Text'; | ||
import Button from '../../components/Button'; | ||
import * as Session from '../../libs/actions/Session'; | ||
import ChangeExpensifyLoginLink from './ChangeExpensifyLoginLink'; | ||
import Terms from './Terms'; | ||
import CONST from '../../CONST'; | ||
import ROUTES from '../../ROUTES'; | ||
import Navigation from '../../libs/Navigation/Navigation'; | ||
import * as ErrorUtils from '../../libs/ErrorUtils'; | ||
import useLocalize from '../../hooks/useLocalize'; | ||
import useNetwork from '../../hooks/useNetwork'; | ||
import useWindowDimensions from '../../hooks/useWindowDimensions'; | ||
import FormHelpMessage from '../../components/FormHelpMessage'; | ||
|
||
const propTypes = { | ||
/* Onyx Props */ | ||
|
||
/** The credentials of the logged in person */ | ||
credentials: PropTypes.shape({ | ||
/** The email/phone the user logged in with */ | ||
login: PropTypes.string, | ||
}), | ||
|
||
/** The details about the account that the user is signing in with */ | ||
account: PropTypes.shape({ | ||
/** Whether or not a sign on form is loading (being submitted) */ | ||
isLoading: PropTypes.bool, | ||
|
||
/** Form that is being loaded */ | ||
loadingForm: PropTypes.oneOf(_.values(CONST.FORMS)), | ||
|
||
/** Whether this account has 2FA enabled or not */ | ||
requiresTwoFactorAuth: PropTypes.bool, | ||
|
||
/** Server-side errors in the submitted authentication code */ | ||
errors: PropTypes.objectOf(PropTypes.string), | ||
}), | ||
|
||
/** Function that returns whether the user is using SAML or magic codes to log in */ | ||
setIsUsingMagicCode: PropTypes.func.isRequired, | ||
}; | ||
|
||
const defaultProps = { | ||
credentials: {}, | ||
account: {}, | ||
}; | ||
|
||
function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}) { | ||
const {translate} = useLocalize(); | ||
const {isOffline} = useNetwork(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
|
||
return ( | ||
<> | ||
<View> | ||
<Text style={[styles.loginHeroBody, styles.mb5, styles.textNormal, !isSmallScreenWidth ? styles.textAlignLeft : {}]}>{translate('samlSignIn.welcomeSAMLEnabled')}</Text> | ||
<Button | ||
isDisabled={isOffline} | ||
success | ||
style={[styles.mv3]} | ||
text={translate('samlSignIn.useSingleSignOn')} | ||
isLoading={account.isLoading} | ||
onPress={() => { | ||
Navigation.navigate(ROUTES.SAML_SIGN_IN); | ||
}} | ||
/> | ||
|
||
<View style={[styles.mt5]}> | ||
<Text style={[styles.loginHeroBody, styles.mb5, styles.textNormal, !isSmallScreenWidth ? styles.textAlignLeft : {}]}> | ||
{translate('samlSignIn.orContinueWithMagicCode')} | ||
</Text> | ||
</View> | ||
|
||
<Button | ||
isDisabled={isOffline} | ||
style={[styles.mv3]} | ||
text={translate('samlSignIn.useMagicCode')} | ||
isLoading={account.isLoading && account.loadingForm === (account.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM)} | ||
onPress={() => { | ||
Session.resendValidateCode(credentials.login); | ||
setIsUsingMagicCode(true); | ||
}} | ||
/> | ||
{Boolean(account) && !_.isEmpty(account.errors) && <FormHelpMessage message={ErrorUtils.getLatestErrorMessage(account)} />} | ||
<ChangeExpensifyLoginLink onPress={() => Session.clearSignInData()} /> | ||
</View> | ||
<View style={[styles.mt5, styles.signInPageWelcomeTextContainer]}> | ||
<Terms /> | ||
</View> | ||
</> | ||
); | ||
} | ||
|
||
ChooseSSOOrMagicCode.propTypes = propTypes; | ||
ChooseSSOOrMagicCode.defaultProps = defaultProps; | ||
ChooseSSOOrMagicCode.displayName = 'ChooseSSOOrMagicCode'; | ||
|
||
export default withOnyx({ | ||
credentials: {key: ONYXKEYS.CREDENTIALS}, | ||
account: {key: ONYXKEYS.ACCOUNT}, | ||
})(ChooseSSOOrMagicCode); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ function LoginForm(props) { | |
useEffect(() => { | ||
// Just call clearAccountMessages on the login page (home route), because when the user is in the transition route and not yet authenticated, | ||
// this component will also be mounted, resetting account.isLoading will cause the app to briefly display the session expiration page. | ||
if (props.isFocused) { | ||
if (props.isFocused && props.isVisible) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is so that if we get an error back in the URL after the user tries to sign in with SSO that we display the error message instead of clearing it. You can test this by navigating to http://localhost:8082/transition?error=meepmeep&exitTo=%2F There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarification - the error is supposed to be displayed on ChooseSSOOrMagicCode or ValidateCodeForm page, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes - I was thinking on the ChooseSSOOrMagicCode view, though then it wouldn't show for SAML required users 🤔 I think that can be handled more fully in a follow up PR though, I'd like to get this merged ASAP so it's easier to develop for the remaining platforms 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good 👍 |
||
Session.clearAccountMessages(); | ||
} | ||
if (!canFocusInputOnScreenFocus() || !input.current || !props.isVisible) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, {useEffect} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import ONYXKEYS from '../../../ONYXKEYS'; | ||
import CONFIG from '../../../CONFIG'; | ||
import Icon from '../../../components/Icon'; | ||
import Text from '../../../components/Text'; | ||
import * as Expensicons from '../../../components/Icon/Expensicons'; | ||
import * as Illustrations from '../../../components/Icon/Illustrations'; | ||
import styles from '../../../styles/styles'; | ||
import themeColors from '../../../styles/themes/default'; | ||
import useLocalize from '../../../hooks/useLocalize'; | ||
|
||
const propTypes = { | ||
/** The credentials of the logged in person */ | ||
credentials: PropTypes.shape({ | ||
/** The email/phone the user logged in with */ | ||
login: PropTypes.string, | ||
}), | ||
}; | ||
|
||
const defaultProps = { | ||
credentials: {}, | ||
}; | ||
|
||
function SAMLSignInPage({credentials}) { | ||
const {translate} = useLocalize(); | ||
|
||
useEffect(() => { | ||
window.open(`${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}`, '_self'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, [credentials.login]); | ||
|
||
return ( | ||
<View style={styles.deeplinkWrapperContainer}> | ||
<View style={styles.deeplinkWrapperMessage}> | ||
<View style={styles.mb2}> | ||
<Icon | ||
width={200} | ||
height={164} | ||
src={Illustrations.RocketBlue} | ||
/> | ||
</View> | ||
<Text style={[styles.textHeadline, styles.textXXLarge, styles.textAlignCenter]}>{translate('samlSignIn.launching')}</Text> | ||
<View style={[styles.mt2, styles.mh2, styles.fontSizeNormal, styles.textAlignCenter]}> | ||
<Text style={[styles.textAlignCenter]}>{translate('samlSignIn.oneMoment')}</Text> | ||
</View> | ||
</View> | ||
<View style={styles.deeplinkWrapperFooter}> | ||
<Icon | ||
width={154} | ||
height={34} | ||
fill={themeColors.success} | ||
src={Expensicons.ExpensifyWordmark} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
SAMLSignInPage.propTypes = propTypes; | ||
SAMLSignInPage.defaultProps = defaultProps; | ||
|
||
export default withOnyx({ | ||
credentials: {key: ONYXKEYS.CREDENTIALS}, | ||
})(SAMLSignInPage); |
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.
The
session
prop appears unused. Do you know if it's needed here?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.
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
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.
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
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.
@NikkiWines if you want to do it as part of #29526 that would be great!
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.
Done!