Skip to content

Commit

Permalink
add SAML flow
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed Dec 4, 2024
1 parent 13180c2 commit 12cfde8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const WRITE_COMMANDS = {
REQUEST_NEW_VALIDATE_CODE: 'RequestNewValidateCode',
SIGN_IN_WITH_APPLE: 'SignInWithApple',
SIGN_IN_WITH_GOOGLE: 'SignInWithGoogle',
SIGN_IN_USER: 'SigninUser',
SIGN_IN_USER_WITH_LINK: 'SigninUserWithLink',
SEARCH: 'Search',
REQUEST_UNLINK_VALIDATION_LINK: 'RequestUnlinkValidationLink',
Expand Down Expand Up @@ -516,6 +517,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.REQUEST_NEW_VALIDATE_CODE]: Parameters.RequestNewValidateCodeParams;
[WRITE_COMMANDS.SIGN_IN_WITH_APPLE]: Parameters.BeginAppleSignInParams;
[WRITE_COMMANDS.SIGN_IN_WITH_GOOGLE]: Parameters.BeginGoogleSignInParams;
[WRITE_COMMANDS.SIGN_IN_USER]: SignInUserParams;
[WRITE_COMMANDS.SIGN_IN_USER_WITH_LINK]: Parameters.SignInUserWithLinkParams;
[WRITE_COMMANDS.REQUEST_UNLINK_VALIDATION_LINK]: Parameters.RequestUnlinkValidationLinkParams;
[WRITE_COMMANDS.UNLINK_LOGIN]: Parameters.UnlinkLoginParams;
Expand Down Expand Up @@ -1027,7 +1029,6 @@ const SIDE_EFFECT_REQUEST_COMMANDS = {
DISCONNECT_AS_DELEGATE: 'DisconnectAsDelegate',
COMPLETE_HYBRID_APP_ONBOARDING: 'CompleteHybridAppOnboarding',
CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP: 'ConnectPolicyToQuickbooksDesktop',
SIGN_IN_USER: 'SigninUser',
} as const;

type SideEffectRequestCommand = ValueOf<typeof SIDE_EFFECT_REQUEST_COMMANDS>;
Expand All @@ -1048,7 +1049,6 @@ type SideEffectRequestCommandParameters = {
[SIDE_EFFECT_REQUEST_COMMANDS.DISCONNECT_AS_DELEGATE]: EmptyObject;
[SIDE_EFFECT_REQUEST_COMMANDS.COMPLETE_HYBRID_APP_ONBOARDING]: EmptyObject;
[SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP]: Parameters.ConnectPolicyToQuickBooksDesktopParams;
[SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER]: SignInUserParams;
};

type ApiRequestCommandParameters = WriteCommandParameters & ReadCommandParameters & SideEffectRequestCommandParameters;
Expand Down
22 changes: 11 additions & 11 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ function signInAttemptState(): OnyxData {
*/
function beginSignIn(email: string) {
const {optimisticData, successData, failureData} = signInAttemptState();
// this data is mocked and should be removed before the merge
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.NVP_TRYNEWDOT,
value: {
classicRedirect: {
dismissed: true,
},
},
});

const params: BeginSignInParams = {email};

Expand Down Expand Up @@ -618,17 +628,7 @@ function signIn(validateCode: string, twoFactorAuthCode?: string) {
params.validateCode = validateCode || credentials.validateCode;
}

// eslint-disable-next-line rulesdir/no-api-side-effects-method
API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.SIGN_IN_USER, params, {
optimisticData,
successData,
failureData,
}).then((response) => {
if (!response) {
return;
}
Onyx.merge(ONYXKEYS.NVP_TRYNEWDOT, {classicRedirect: {dismissed: !response.tryNewDot}});
});
API.write(WRITE_COMMANDS.SIGN_IN_USER, params, {optimisticData, successData, failureData});
});
}

Expand Down
13 changes: 11 additions & 2 deletions src/pages/signin/ChooseSSOOrMagicCode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect} from 'react';
import {Keyboard, View} from 'react-native';
import {Keyboard, NativeModules, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
Expand All @@ -12,6 +12,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as HybridAppActions from '@userActions/HybridApp';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -61,6 +62,7 @@ function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: Choos
text={translate('samlSignIn.useSingleSignOn')}
isLoading={account?.isLoading}
onPress={() => {
HybridAppActions.setNewDotSignInState(CONST.HYBRID_APP_SIGN_IN_STATE.STARTED);
Navigation.navigate(ROUTES.SAML_SIGN_IN);
}}
/>
Expand All @@ -83,7 +85,14 @@ function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: Choos
}}
/>
{!!account && !isEmptyObject(account.errors) && <FormHelpMessage message={ErrorUtils.getLatestErrorMessage(account)} />}
<ChangeExpensifyLoginLink onPress={() => Session.clearSignInData()} />
<ChangeExpensifyLoginLink
onPress={() => {
if (NativeModules.HybridAppModule) {
HybridAppActions.resetSignInFlow();
}
Session.clearSignInData();
}}
/>
</View>
<View style={[styles.mt5, styles.signInPageWelcomeTextContainer]}>
<Terms />
Expand Down
5 changes: 5 additions & 0 deletions src/pages/signin/SAMLSignInPage/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useCallback, useState} from 'react';
import {NativeModules} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import WebView from 'react-native-webview';
import type {WebViewNativeEvent} from 'react-native-webview/lib/WebViewTypes';
Expand All @@ -9,6 +10,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import getPlatform from '@libs/getPlatform';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as HybridAppActions from '@userActions/HybridApp';
import * as Session from '@userActions/Session';
import CONFIG from '@src/CONFIG';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -58,6 +60,9 @@ function SAMLSignInPage() {
<HeaderWithBackButton
title=""
onBackButtonPress={() => {
if (NativeModules.HybridAppModule) {
HybridAppActions.resetSignInFlow();
}
Session.clearSignInData();
Navigation.isNavigationReady().then(() => {
Navigation.goBack();
Expand Down

0 comments on commit 12cfde8

Please sign in to comment.