mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-06 22:19:41 +03:00
Merge pull request #1997 from ecency/nt/token-refresh
inverted migration logic, support for other secret keys to generate p…
This commit is contained in:
commit
217285be95
@ -92,8 +92,8 @@ const AccountsBottomSheetContainer = ({ navigation }) => {
|
|||||||
//migreate account to use access token for master key auth type
|
//migreate account to use access token for master key auth type
|
||||||
let logs = "Realm data: " + JSON.stringify(realmData) + "\n\n"
|
let logs = "Realm data: " + JSON.stringify(realmData) + "\n\n"
|
||||||
Alert.alert("Realm data: " + JSON.stringify(realmData) + "\n\nWith PinHash: " + pinHash + "\n\n" )
|
Alert.alert("Realm data: " + JSON.stringify(realmData) + "\n\nWith PinHash: " + pinHash + "\n\n" )
|
||||||
if (realmData[0].authType === AUTH_TYPE.MASTER_KEY && realmData[0].accessToken === '') {
|
if (realmData[0].authType !== AUTH_TYPE.STEEM_CONNECT && realmData[0].accessToken === '') {
|
||||||
_currentAccount = await migrateToMasterKeyWithAccessToken(_currentAccount, pinHash);
|
_currentAccount = await migrateToMasterKeyWithAccessToken(_currentAccount, realmData[0], pinHash);
|
||||||
logs += "Migrated Data: " + JSON.stringify(_currentAccount.local);
|
logs += "Migrated Data: " + JSON.stringify(_currentAccount.local);
|
||||||
Alert.alert("Migrated Data: " + JSON.stringify(_currentAccount.local))
|
Alert.alert("Migrated Data: " + JSON.stringify(_currentAccount.local))
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import sha256 from 'crypto-js/sha256';
|
|||||||
import Config from 'react-native-config';
|
import Config from 'react-native-config';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
|
|
||||||
|
import { Alert } from 'react-native';
|
||||||
import { getDigitPinCode, getUser } from './dhive';
|
import { getDigitPinCode, getUser } from './dhive';
|
||||||
import {
|
import {
|
||||||
setUserData,
|
setUserData,
|
||||||
@ -333,7 +334,7 @@ export const refreshSCToken = async (userData, pinCode) => {
|
|||||||
});
|
});
|
||||||
return encryptedAccessToken;
|
return encryptedAccessToken;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Alert.alert("Access token refresh failed", JSON.stringify(error));
|
Alert.alert('Access token refresh failed', JSON.stringify(error));
|
||||||
if (now > expireDate) {
|
if (now > expireDate) {
|
||||||
throw error;
|
throw error;
|
||||||
} else {
|
} else {
|
||||||
@ -421,25 +422,22 @@ const isLoggedInUser = async (username) => {
|
|||||||
* This migration snippet is used to update access token for users logged in using masterKey
|
* This migration snippet is used to update access token for users logged in using masterKey
|
||||||
* accessToken is required for all ecency api calls even for non hivesigner users.
|
* accessToken is required for all ecency api calls even for non hivesigner users.
|
||||||
*/
|
*/
|
||||||
export const migrateToMasterKeyWithAccessToken = async (account, pinHash) => {
|
export const migrateToMasterKeyWithAccessToken = async (account, userData, pinHash) => {
|
||||||
//get username, user local data from account;
|
//get username, user local data from account;
|
||||||
const username = account.name;
|
const username = account.name;
|
||||||
const userData = account.local;
|
|
||||||
|
|
||||||
if (userData.accessToken) {
|
|
||||||
//skipping migration as access token already preset;
|
|
||||||
Alert.alert("Already have access token: " + JSON.stringify(userData));
|
|
||||||
return account;
|
|
||||||
}
|
|
||||||
|
|
||||||
//decrypt password from local data
|
//decrypt password from local data
|
||||||
const pinCode = getDigitPinCode(pinHash);
|
const pinCode = getDigitPinCode(pinHash);
|
||||||
const password = decryptKey(userData.masterKey, pinCode);
|
const password = decryptKey(
|
||||||
|
userData.masterKey || userData.activeKey || userData.postingKey || userData.memoKey,
|
||||||
|
pinCode,
|
||||||
|
);
|
||||||
|
|
||||||
// Set private keys of user
|
// Set private keys of user
|
||||||
const privateKeys = getPrivateKeys(username, password);
|
const privateKeys = getPrivateKeys(username, password);
|
||||||
|
|
||||||
const signerPrivateKey = privateKeys.ownerKey || privateKeys.activeKey || privateKeys.postingKey;
|
const signerPrivateKey =
|
||||||
|
privateKeys.ownerKey || privateKeys.activeKey || privateKeys.postingKey || privateKeys.memoKey;
|
||||||
const code = await makeHsCode(account.name, signerPrivateKey);
|
const code = await makeHsCode(account.name, signerPrivateKey);
|
||||||
const scTokens = await getSCAccessToken(code);
|
const scTokens = await getSCAccessToken(code);
|
||||||
|
|
||||||
|
@ -693,8 +693,8 @@ class ApplicationContainer extends Component {
|
|||||||
//cannot migrate or refresh token since pin would null while pin code modal is open
|
//cannot migrate or refresh token since pin would null while pin code modal is open
|
||||||
if (!isPinCodeOpen) {
|
if (!isPinCodeOpen) {
|
||||||
//migration script for previously mast key based logged in user not having access token
|
//migration script for previously mast key based logged in user not having access token
|
||||||
if (realmObject.authType === AUTH_TYPE.MASTER_KEY && realmObject.accessToken === '') {
|
if (realmObject.authType !== AUTH_TYPE.STEEM_CONNECT && realmObject.accessToken === '') {
|
||||||
accountData = await migrateToMasterKeyWithAccessToken(accountData, pinCode);
|
accountData = await migrateToMasterKeyWithAccessToken(accountData, realmObject, pinCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
//refresh access token
|
//refresh access token
|
||||||
@ -873,8 +873,12 @@ class ApplicationContainer extends Component {
|
|||||||
[_currentAccount.local] = realmData;
|
[_currentAccount.local] = realmData;
|
||||||
|
|
||||||
//migreate account to use access token for master key auth type
|
//migreate account to use access token for master key auth type
|
||||||
if (realmData[0].authType === AUTH_TYPE.MASTER_KEY && realmData[0].accessToken === '') {
|
if (realmData[0].authType !== AUTH_TYPE.STEEM_CONNECT && realmData[0].accessToken === '') {
|
||||||
_currentAccount = await migrateToMasterKeyWithAccessToken(_currentAccount, pinCode);
|
_currentAccount = await migrateToMasterKeyWithAccessToken(
|
||||||
|
_currentAccount,
|
||||||
|
realmData[0],
|
||||||
|
pinCode,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//update refresh token
|
//update refresh token
|
||||||
|
@ -299,11 +299,12 @@ class PinCodeContainer extends Component {
|
|||||||
const pinHash = encryptKey(pin, Config.PIN_KEY);
|
const pinHash = encryptKey(pin, Config.PIN_KEY);
|
||||||
//migration script for previously mast key based logged in user not having access token
|
//migration script for previously mast key based logged in user not having access token
|
||||||
if (
|
if (
|
||||||
realmData[0].authType === AUTH_TYPE.MASTER_KEY &&
|
realmData[0].authType !== AUTH_TYPE.STEEM_CONNECT &&
|
||||||
realmData[0].accessToken === ''
|
realmData[0].accessToken === ''
|
||||||
) {
|
) {
|
||||||
_currentAccount = await migrateToMasterKeyWithAccessToken(
|
_currentAccount = await migrateToMasterKeyWithAccessToken(
|
||||||
_currentAccount,
|
_currentAccount,
|
||||||
|
realmData[0],
|
||||||
pinHash,
|
pinHash,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user