Skip to content

Commit

Permalink
Merge pull request #34930 from Expensify/arosiclair-saml-logging-and-…
Browse files Browse the repository at this point in the history
…checks

Add logging and loading checks for short lived authToken sign-ins
  • Loading branch information
thienlnam authored Jan 25, 2024
2 parents 08e9276 + 420878d commit c6463dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/pages/LogInWithShortLivedAuthTokenPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import type {PublicScreensParamList} from '@libs/Navigation/types';
import * as Session from '@userActions/Session';
Expand All @@ -38,6 +39,7 @@ function LogInWithShortLivedAuthTokenPage({route, account}: LogInWithShortLivedA

// Try to authenticate using the shortLivedToken if we're not already trying to load the accounts
if (token && !account?.isLoading) {
Log.info('LogInWithShortLivedAuthTokenPage - Successfully received shortLivedAuthToken. Signing in...');
Session.signInWithShortLivedAuthToken(email, token);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/LogOutPreviousUserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {useEffect} from 'react';
import {Linking} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Log from '@libs/Log';
import * as SessionUtils from '@libs/SessionUtils';
import * as Session from '@userActions/Session';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -51,6 +52,7 @@ function LogOutPreviousUserPage(props) {
// On Enabling 2FA, authToken stored in Onyx becomes expired and hence we need to fetch new authToken
const shouldForceLogin = lodashGet(props, 'route.params.shouldForceLogin', '') === 'true';
if (shouldForceLogin) {
Log.info('LogOutPreviousUserPage - forcing login with shortLivedAuthToken');
const email = lodashGet(props, 'route.params.email', '');
const shortLivedAuthToken = lodashGet(props, 'route.params.shortLivedAuthToken', '');
Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
Expand Down
17 changes: 14 additions & 3 deletions src/pages/signin/SAMLSignInPage/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator';
import ScreenWrapper from '@components/ScreenWrapper';
import getPlatform from '@libs/getPlatform';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as Session from '@userActions/Session';
import CONFIG from '@src/CONFIG';
Expand All @@ -19,13 +20,20 @@ const propTypes = {
/** The email/phone the user logged in with */
login: PropTypes.string,
}),

/** State of the logging in user's account */
account: PropTypes.shape({
/** Whether the account is loading */
isLoading: PropTypes.bool,
}),
};

const defaultProps = {
credentials: {},
account: {},
};

function SAMLSignInPage({credentials}) {
function SAMLSignInPage({credentials, account}) {
const samlLoginURL = `${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}&platform=${getPlatform()}`;
const [showNavigation, shouldShowNavigation] = useState(true);

Expand All @@ -36,13 +44,15 @@ function SAMLSignInPage({credentials}) {
*/
const handleNavigationStateChange = useCallback(
({url}) => {
Log.info('SAMLSignInPage - Handling SAML navigation change');
// If we've gotten a callback then remove the option to navigate back to the sign in page
if (url.includes('loginCallback')) {
shouldShowNavigation(false);
}

const searchParams = new URLSearchParams(new URL(url).search);
if (searchParams.has('shortLivedAuthToken')) {
if (searchParams.has('shortLivedAuthToken') && !account.isLoading) {
Log.info('SAMLSignInPage - Successfully received shortLivedAuthToken. Signing in...');
const shortLivedAuthToken = searchParams.get('shortLivedAuthToken');
Session.signInWithShortLivedAuthToken(credentials.login, shortLivedAuthToken);
}
Expand All @@ -54,7 +64,7 @@ function SAMLSignInPage({credentials}) {
Navigation.navigate(ROUTES.HOME);
}
},
[credentials.login, shouldShowNavigation],
[credentials.login, shouldShowNavigation, account.isLoading],
);

return (
Expand Down Expand Up @@ -92,4 +102,5 @@ SAMLSignInPage.displayName = 'SAMLSignInPage';

export default withOnyx({
credentials: {key: ONYXKEYS.CREDENTIALS},
account: {key: ONYXKEYS.ACCOUNT},
})(SAMLSignInPage);

0 comments on commit c6463dc

Please sign in to comment.