diff options
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 9 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 1 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 12 | ||||
| -rw-r--r-- | gui/src/shared/ipc-event-channel.ts | 5 |
4 files changed, 26 insertions, 1 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index 1ce4450af3..6105f75c56 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -428,6 +428,15 @@ export class DaemonRpc { } } + public async getWwwAuthToken(): Promise<string> { + const response = await this.transport.send('get_www_auth_token'); + try { + return validate(string, response); + } catch (error) { + throw new ResponseParseError('Invalid response from get_www_auth_token', error); + } + } + public async getRelayLocations(): Promise<IRelayList> { const response = await this.transport.send('get_relay_locations'); try { diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 5b5c58d108..9397d45467 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -991,6 +991,7 @@ class ApplicationMain { IpcMainEventChannel.account.handleLogin((token: AccountToken) => this.login(token)); IpcMainEventChannel.account.handleLogout(() => this.logout()); + IpcMainEventChannel.account.handleWwwAuthToken(() => this.daemonRpc.getWwwAuthToken()); IpcMainEventChannel.accountHistory.handleRemoveItem(async (token: AccountToken) => { await this.daemonRpc.removeAccountFromHistory(token); diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index f9c2390b25..ce7c00c55d 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -3,7 +3,7 @@ import { push as pushHistory, replace as replaceHistory, } from 'connected-react-router'; -import { ipcRenderer, webFrame } from 'electron'; +import { ipcRenderer, shell, webFrame } from 'electron'; import log from 'electron-log'; import { createMemoryHistory } from 'history'; import * as React from 'react'; @@ -288,6 +288,16 @@ export default class AppRenderer { return IpcRendererEventChannel.accountHistory.removeItem(accountToken); } + public async openLinkWithAuth(link: string) { + let token; + try { + token = await IpcRendererEventChannel.account.getWwwAuthToken(); + } catch (e) { + token = ''; + } + shell.openExternal(`${link}?token=${token}`); + } + public async setAllowLan(allowLan: boolean) { const actions = this.reduxActions; await IpcRendererEventChannel.settings.setAllowLan(allowLan); diff --git a/gui/src/shared/ipc-event-channel.ts b/gui/src/shared/ipc-event-channel.ts index 8a1a31c2d4..a612660c99 100644 --- a/gui/src/shared/ipc-event-channel.ts +++ b/gui/src/shared/ipc-event-channel.ts @@ -102,11 +102,13 @@ interface IGuiSettingsHandlers extends ISender<IGuiSettingsState> { interface IAccountHandlers extends ISender<IAccountData | undefined> { handleLogin(fn: (token: AccountToken) => Promise<void>): void; handleLogout(fn: () => Promise<void>): void; + handleWwwAuthToken(fn: () => Promise<string>): void; } interface IAccountMethods extends IReceiver<IAccountData | undefined> { login(token: AccountToken): Promise<void>; logout(): Promise<void>; + getWwwAuthToken(): Promise<string>; } interface IAccountHistoryHandlers extends ISender<AccountToken[]> { @@ -177,6 +179,7 @@ const REMOVE_ACCOUNT_HISTORY_ITEM = 'remove-account-history-item'; const DO_LOGIN = 'do-login'; const DO_LOGOUT = 'do-logout'; +const DO_GET_WWW_AUTH_TOKEN = 'do-get-www-auth-token'; const ACCOUNT_DATA_CHANGED = 'account-data-changed'; const AUTO_START_CHANGED = 'auto-start-changed'; @@ -267,6 +270,7 @@ export class IpcRendererEventChannel { listen: listen(ACCOUNT_DATA_CHANGED), login: requestSender(DO_LOGIN), logout: requestSender(DO_LOGOUT), + getWwwAuthToken: requestSender(DO_GET_WWW_AUTH_TOKEN), }; public static accountHistory: IAccountHistoryMethods = { @@ -358,6 +362,7 @@ export class IpcMainEventChannel { notify: sender<IAccountData | undefined>(ACCOUNT_DATA_CHANGED), handleLogin: requestHandler(DO_LOGIN), handleLogout: requestHandler(DO_LOGOUT), + handleWwwAuthToken: requestHandler(DO_GET_WWW_AUTH_TOKEN), }; public static accountHistory: IAccountHistoryHandlers = { |
