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

Use CreateLogin authToken instead of relying on reauthenticate #5438

Merged
merged 6 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ function reauthenticate(command = '') {
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
partnerUserID: credentials.autoGeneratedLogin,
partnerUserSecret: credentials.autoGeneratedPassword,
authToken,
})
.then((response) => {
// If authentication fails throw so that we hit
Expand Down
19 changes: 8 additions & 11 deletions src/libs/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ function fetchAccountDetails(login) {
* re-authenticating after an authToken expires.
*
* @param {String} authToken
* @param {String} encryptedAuthToken – Not required for the CreateLogin API call, but passed to setSuccessfulSignInData
* @param {String} email
* @return {Promise}
*/
function createTemporaryLogin(authToken, encryptedAuthToken, email) {
function createTemporaryLogin(authToken, email) {
const autoGeneratedLogin = Str.guid('expensify.cash-');
const autoGeneratedPassword = Str.guid();

Expand All @@ -182,13 +181,14 @@ function createTemporaryLogin(authToken, encryptedAuthToken, email) {
doNotRetry: true,
forceNetworkRequest: true,
email,
includeEncryptedAuthToken: true,
})
.then((createLoginResponse) => {
if (createLoginResponse.jsonCode !== 200) {
throw new Error(createLoginResponse.message);
}

setSuccessfulSignInData({...createLoginResponse, encryptedAuthToken});
setSuccessfulSignInData(createLoginResponse);

// If we have an old generated login for some reason
// we should delete it before storing the new details
Expand Down Expand Up @@ -237,9 +237,8 @@ function signIn(password, twoFactorAuthCode) {
twoFactorAuthCode,
email: credentials.login,
})
.then((authenticateResponse) => {
const {authToken, encryptedAuthToken, email} = authenticateResponse;
createTemporaryLogin(authToken, encryptedAuthToken, email);
.then(({authToken, email}) => {
createTemporaryLogin(authToken, email);
})
.catch((error) => {
Onyx.merge(ONYXKEYS.ACCOUNT, {error: translateLocal(error.message), loading: false});
Expand All @@ -252,14 +251,12 @@ function signIn(password, twoFactorAuthCode) {
* @param {String} accountID
* @param {String} email
* @param {String} shortLivedToken
* @param {string} encryptedAuthToken
*/
function signInWithShortLivedToken(accountID, email, shortLivedToken, encryptedAuthToken) {
function signInWithShortLivedToken(accountID, email, shortLivedToken) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true});

createTemporaryLogin(shortLivedToken, encryptedAuthToken, email).then((response) => {
createTemporaryLogin(shortLivedToken, email).then((response) => {
Onyx.merge(ONYXKEYS.SESSION, {
authToken: shortLivedToken,
accountID,
email,
});
Expand Down Expand Up @@ -305,7 +302,7 @@ function setPassword(password, validateCode, accountID) {
})
.then((response) => {
if (response.jsonCode === 200) {
createTemporaryLogin(response.authToken, response.encryptedAuthToken, response.email);
createTemporaryLogin(response.authToken, response.email);
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/pages/LogInWithShortLivedTokenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ class LogInWithShortLivedTokenPage extends Component {
const accountID = parseInt(lodashGet(this.props.route.params, 'accountID', ''), 10);
const email = lodashGet(this.props.route.params, 'email', '');
const shortLivedToken = lodashGet(this.props.route.params, 'shortLivedToken', '');
const encryptedAuthToken = lodashGet(this.props.route.params, 'encryptedAuthToken', '');

// If the user is revisiting the component authenticated with the right account, we don't need to do anything, the componentWillUpdate when betas are loaded and redirect
if (this.props.session.authToken && email === this.props.session.email) {
return;
}

signInWithShortLivedToken(accountID, email, shortLivedToken, encryptedAuthToken);
signInWithShortLivedToken(accountID, email, shortLivedToken);
}

componentDidUpdate() {
Expand Down