-
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 #3597 from Expensify/Rory-UseEncryptedAuthToken
Use encrypted auth token for images
- Loading branch information
Showing
10 changed files
with
89 additions
and
113 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
src/components/AnchorForCommentsOnly/AnchorWithAuthToken.js
This file was deleted.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
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,19 @@ | ||
import lodashGet from 'lodash/get'; | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
|
||
let encryptedAuthToken = ''; | ||
Onyx.connect({ | ||
key: ONYXKEYS.SESSION, | ||
callback: session => encryptedAuthToken = lodashGet(session, 'encryptedAuthToken', ''), | ||
}); | ||
|
||
/** | ||
* Add encryptedAuthToken to this attachment URL | ||
* | ||
* @param {String} url | ||
* @returns {String} | ||
*/ | ||
export default function (url) { | ||
return `${url}?encryptedAuthToken=${encryptedAuthToken}`; | ||
} |
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,41 @@ | ||
import _ from 'underscore'; | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import {reauthenticate} from '../API'; | ||
|
||
/** | ||
* This migration adds an encryptedAuthToken to the SESSION key, if it is not present. | ||
* | ||
* @returns {Promise} | ||
*/ | ||
export default function () { | ||
return new Promise((resolve) => { | ||
const connectionID = Onyx.connect({ | ||
key: ONYXKEYS.SESSION, | ||
callback: (session) => { | ||
Onyx.disconnect(connectionID); | ||
|
||
if (session && !_.isEmpty(session.encryptedAuthToken)) { | ||
console.debug('[Migrate Onyx] Skipped migration AddEncryptedAuthToken'); | ||
return resolve(); | ||
} | ||
|
||
if (!session || !session.authToken) { | ||
console.debug('[Migrate Onyx] Skipped migration AddEncryptedAuthToken'); | ||
return resolve(); | ||
} | ||
|
||
// If there is an auth token but no encrypted auth token, reauthenticate. | ||
if (session.authToken && _.isUndefined(session.encryptedAuthToken)) { | ||
return reauthenticate('Onyx_Migration_AddEncryptedAuthToken') | ||
.then(() => { | ||
console.debug('[Migrate Onyx] Ran migration AddEncryptedAuthToken'); | ||
return resolve(); | ||
}); | ||
} | ||
|
||
return resolve(); | ||
}, | ||
}); | ||
}); | ||
} |