This commit is contained in:
Sean Yesmunt 2020-01-16 17:03:41 -05:00
parent 939a7d7689
commit 5c906df371
5 changed files with 34 additions and 50 deletions

View file

@ -318,14 +318,9 @@ ipcMain.on('version-info-requested', () => {
requestLatestRelease(); requestLatestRelease();
}); });
// In a few months, we can remove the keytar dependency and below calls once // In a few months, we can remove the keytar dependency and below calls once
// enough users have moved over to cookies // enough users have moved over to cookies
ipcMain.on('get-auth-token', event => {
keytar.getPassword('LBRY', 'auth_token').then(token => {
event.sender.send('auth-token-response', token ? token.toString().trim() : null);
});
});
ipcMain.on('delete-auth-token', (event, password) => { ipcMain.on('delete-auth-token', (event, password) => {
keytar.deletePassword('LBRY', 'auth_token', password).then(res => { keytar.deletePassword('LBRY', 'auth_token', password).then(res => {
event.sender.send('delete-auth-token-response', res); event.sender.send('delete-auth-token-response', res);
@ -338,14 +333,6 @@ ipcMain.on('get-password', event => {
}); });
}); });
ipcMain.on('set-password', (event, password) => {
if (password || password === '') {
keytar.setPassword('LBRY', 'wallet_password', password).then(res => {
event.sender.send('set-password-response', res);
});
}
});
ipcMain.on('delete-password', event => { ipcMain.on('delete-password', event => {
keytar.deletePassword('LBRY', 'wallet_password').then(res => { keytar.deletePassword('LBRY', 'wallet_password').then(res => {
event.sender.send('delete-password-response', res); event.sender.send('delete-password-response', res);

View file

@ -108,7 +108,6 @@ Lbryio.setOverride(
authToken = response.auth_token; authToken = response.auth_token;
setAuthToken(authToken); setAuthToken(authToken);
resolve(authToken); resolve(authToken);
}); });
}) })
@ -118,23 +117,6 @@ Lbryio.setOverride(
'getAuthToken', 'getAuthToken',
() => () =>
new Promise(resolve => { new Promise(resolve => {
// @if TARGET='app'
// NEED TO DO SOMETHING HERE TO CHECK FOR A COOKIE AUTH TOKEN.
// IF IT EXISTS, SKIP AND CONTINUE BELOW THE @ENDIF
// IF NOT, COPY THE KEYTAR AUTH TOKEN AND PASSWORD TO THE COOKIE (SetAuthToken/SetPassword?)
// AND THEN DELETE KEYTAR ONE (Or leave for now?)
if (authToken) {
resolve(authToken);
}
ipcRenderer.once('auth-token-response', (event, token) => {
Lbryio.authToken = token;
resolve(token);
});
ipcRenderer.send('get-auth-token');
// @endif
const authTokenToReturn = authToken || getAuthToken(); const authTokenToReturn = authToken || getAuthToken();
if (authTokenToReturn !== null) { if (authTokenToReturn !== null) {

View file

@ -35,9 +35,7 @@ class ModalDownloading extends React.PureComponent<Props> {
<p>{__('After the install is complete, please reopen the app.')}</p> <p>{__('After the install is complete, please reopen the app.')}</p>
<p> <p>
{__('Note: You can also install the AppImage version for streamlined updates.')}{' '} {__('Note: You can also install the AppImage version for streamlined updates.')}{' '}
<span style={{ whiteSpace: 'nowrap' }}>
<Button button="link" label={__('Download here.')} href="https://lbry.com/get/lbry.AppImage" /> <Button button="link" label={__('Download here.')} href="https://lbry.com/get/lbry.AppImage" />
</span>
</p> </p>
</React.Fragment> </React.Fragment>
) : null} ) : null}

View file

@ -6,11 +6,11 @@ const isProduction = process.env.NODE_ENV === 'production';
const maxExpiration = 2147483647; const maxExpiration = 2147483647;
let sessionPassword; let sessionPassword;
function setCookie(name: string, value: string, days: number) { function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
let expires = ''; let expires = '';
if (days) { if (expirationDaysOnWeb) {
let date = new Date(); let date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); date.setTime(date.getTime() + expirationDaysOnWeb * 24 * 60 * 60 * 1000);
// If on PC, set to not expire (max) // If on PC, set to not expire (max)
expires = `expires=${IS_WEB ? date.toUTCString() : maxExpiration};`; expires = `expires=${IS_WEB ? date.toUTCString() : maxExpiration};`;
} }
@ -76,20 +76,32 @@ export const getSavedPassword = () => {
export const getKeychainPassword = () => { export const getKeychainPassword = () => {
return new Promise<*>(resolve => { return new Promise<*>(resolve => {
const password = getCookie('saved-password'); let password;
if (password) { // @if TARGET='web'
// In the future, this will be the only code in this function
// Handling keytar stuff separately so we can easily rip it out later
password = getCookie('saved-password');
resolve(password); resolve(password);
} // @endif
// We can remove this when we remove keytar
else {
ipcRenderer.once('get-password-response', (event, password) => {
resolve(password);
});
ipcRenderer.send('get-password');
}
// @if TARGET='app' // @if TARGET='app'
password = getCookie('saved-password');
if (password) {
resolve(password);
} else {
// No password saved in a cookie, get it from the keychain, then delete the value in the keychain
ipcRenderer.once('get-password-response', (event, keychainPassword) => {
resolve(keychainPassword);
if (keychainPassword) {
setSavedPassword(keychainPassword, true);
ipcRenderer.send('delete-password');
}
});
ipcRenderer.send('get-password');
}
// @endif // @endif
}); });
}; };
@ -121,6 +133,11 @@ export const doSignOutCleanup = () => {
deleteCookie('auth_token'); deleteCookie('auth_token');
deleteCookie('saved-password'); deleteCookie('saved-password');
resolve(); resolve();
// @if TARGET='app'
ipcRenderer.send('delete-auth-token');
ipcRenderer.send('delete-password');
// @endif;
}); });
}; };