fallback to keychain for auth_token if desktop users don't have an auth_token cookie
This commit is contained in:
parent
af3c2e2a63
commit
c321db4cab
2 changed files with 28 additions and 0 deletions
|
@ -321,6 +321,12 @@ ipcMain.on('version-info-requested', () => {
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
22
ui/index.jsx
22
ui/index.jsx
|
@ -117,6 +117,27 @@ Lbryio.setOverride(
|
||||||
'getAuthToken',
|
'getAuthToken',
|
||||||
() =>
|
() =>
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
|
// @if TARGET='app'
|
||||||
|
const desktopAuthTokenToReturn = authToken || getAuthToken();
|
||||||
|
|
||||||
|
if (desktopAuthTokenToReturn) {
|
||||||
|
resolve(desktopAuthTokenToReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Old users who haven't moved to storing the auth_token in a cookie
|
||||||
|
// Get it => set it => delete from keychain
|
||||||
|
ipcRenderer.once('auth-token-response', (event, keychainToken) => {
|
||||||
|
Lbryio.authToken = keychainToken;
|
||||||
|
setAuthToken(keychainToken);
|
||||||
|
resolve(keychainToken);
|
||||||
|
|
||||||
|
ipcRenderer.send('delete-auth-token');
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcRenderer.send('get-auth-token');
|
||||||
|
// @endif
|
||||||
|
|
||||||
|
// @if TARGET='web'
|
||||||
const authTokenToReturn = authToken || getAuthToken();
|
const authTokenToReturn = authToken || getAuthToken();
|
||||||
|
|
||||||
if (authTokenToReturn !== null) {
|
if (authTokenToReturn !== null) {
|
||||||
|
@ -124,6 +145,7 @@ Lbryio.setOverride(
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(authTokenToReturn);
|
resolve(authTokenToReturn);
|
||||||
|
// @endif
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue