-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29526 from Expensify/nikki-saml-newdot-ios
Add iOS and Android view for SAML Login
- Loading branch information
Showing
6 changed files
with
156 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import {StyleSheet, View} from 'react-native'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import styles from '@styles/styles'; | ||
import themeColors from '@styles/themes/default'; | ||
import Icon from './Icon'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import * as Illustrations from './Icon/Illustrations'; | ||
import Text from './Text'; | ||
|
||
function SAMLLoadingIndicator() { | ||
const {translate} = useLocalize(); | ||
return ( | ||
<View style={[StyleSheet.absoluteFillObject, 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> | ||
); | ||
} | ||
|
||
SAMLLoadingIndicator.displayName = 'SAMLLoadingIndicator'; | ||
|
||
export default SAMLLoadingIndicator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {useCallback, useState} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import WebView from 'react-native-webview'; | ||
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; | ||
import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; | ||
import ScreenWrapper from '@components/ScreenWrapper'; | ||
import getPlatform from '@libs/getPlatform'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as Session from '@userActions/Session'; | ||
import CONFIG from '@src/CONFIG'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
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 samlLoginURL = `${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}&platform=${getPlatform()}`; | ||
const [showNavigation, shouldShowNavigation] = useState(true); | ||
|
||
/** | ||
* Handles in-app navigation once we get a response back from Expensify | ||
* | ||
* @param {String} params.url | ||
*/ | ||
const handleNavigationStateChange = useCallback( | ||
({url}) => { | ||
// 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')) { | ||
const shortLivedAuthToken = searchParams.get('shortLivedAuthToken'); | ||
Session.signInWithShortLivedAuthToken(credentials.login, shortLivedAuthToken); | ||
} | ||
|
||
// If the login attempt is unsuccessful, set the error message for the account and redirect to sign in page | ||
if (searchParams.has('error')) { | ||
Session.clearSignInData(); | ||
Session.setAccountError(searchParams.get('error')); | ||
Navigation.navigate(ROUTES.HOME); | ||
} | ||
}, | ||
[credentials.login, shouldShowNavigation], | ||
); | ||
|
||
return ( | ||
<ScreenWrapper | ||
shouldShowOfflineIndicator={false} | ||
includeSafeAreaPaddingBottom={false} | ||
testID={SAMLSignInPage.displayName} | ||
> | ||
{showNavigation && ( | ||
<HeaderWithBackButton | ||
title="" | ||
onBackButtonPress={() => { | ||
Session.clearSignInData(); | ||
Navigation.navigate(ROUTES.HOME); | ||
}} | ||
/> | ||
)} | ||
<FullPageOfflineBlockingView> | ||
<WebView | ||
originWhitelist={['https://*']} | ||
source={{uri: samlLoginURL}} | ||
incognito // 'incognito' prop required for Android, issue here https://github.com/react-native-webview/react-native-webview/issues/1352 | ||
startInLoadingState | ||
renderLoading={() => <SAMLLoadingIndicator />} | ||
onNavigationStateChange={handleNavigationStateChange} | ||
/> | ||
</FullPageOfflineBlockingView> | ||
</ScreenWrapper> | ||
); | ||
} | ||
|
||
SAMLSignInPage.propTypes = propTypes; | ||
SAMLSignInPage.defaultProps = defaultProps; | ||
SAMLSignInPage.displayName = 'SAMLSignInPage'; | ||
|
||
export default withOnyx({ | ||
credentials: {key: ONYXKEYS.CREDENTIALS}, | ||
})(SAMLSignInPage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters