diff --git a/packages/app-desktop/gui/ClipperConfigScreen.jsx b/packages/app-desktop/gui/ClipperConfigScreen.jsx index 20e31b51b..be5d0b628 100644 --- a/packages/app-desktop/gui/ClipperConfigScreen.jsx +++ b/packages/app-desktop/gui/ClipperConfigScreen.jsx @@ -7,6 +7,7 @@ const ClipperServer = require('@joplin/lib/ClipperServer'); const Setting = require('@joplin/lib/models/Setting').default; const { clipboard } = require('electron'); const ExtensionBadge = require('./ExtensionBadge.min'); +const EncryptionService = require('@joplin/lib/services/EncryptionService').default; class ClipperConfigScreenComponent extends React.Component { constructor() { @@ -39,6 +40,16 @@ class ClipperConfigScreenComponent extends React.Component { alert(_('Token has been copied to the clipboard!')); } + renewToken_click() { + if (confirm(_('Are you sure you want to renew the authorisation token?'))) { + void EncryptionService.instance() + .generateApiToken() + .then((token: string) => { + Setting.setValue('api.token', token); + }); + } + } + render() { const theme = themeStyle(this.props.themeId); @@ -59,6 +70,10 @@ class ClipperConfigScreenComponent extends React.Component { backgroundColor: theme.backgroundColor, }; + const tokenStyle = { + fontFamily: 'monospace', + }; + const webClipperStatusComps = []; if (this.props.clipperServerAutoStart) { @@ -131,12 +146,17 @@ class ClipperConfigScreenComponent extends React.Component {

{_('Advanced options')}

{_('Authorisation token:')}

- {this.props.apiToken}{' '} + {this.props.apiToken}{' '} {_('Copy token')}

{_('This authorisation token is only needed to allow third-party applications to access Joplin.')}

+
+ +
diff --git a/packages/lib/BaseApplication.ts b/packages/lib/BaseApplication.ts index 4ee4b9d55..dc2531fc9 100644 --- a/packages/lib/BaseApplication.ts +++ b/packages/lib/BaseApplication.ts @@ -776,7 +776,7 @@ export default class BaseApplication { if (!Setting.value('api.token')) { void EncryptionService.instance() - .randomHexString(64) + .generateApiToken() .then((token: string) => { Setting.setValue('api.token', token); }); diff --git a/packages/lib/services/EncryptionService.ts b/packages/lib/services/EncryptionService.ts index 3751f4b51..5cbbcaea5 100644 --- a/packages/lib/services/EncryptionService.ts +++ b/packages/lib/services/EncryptionService.ts @@ -254,6 +254,10 @@ export default class EncryptionService { // sjcl.random.addEntropy(hexSeed, 1024, 'shim.randomBytes'); // } + async generateApiToken() { + return await this.randomHexString(64); + } + async randomHexString(byteCount: number) { const bytes: any[] = await shim.randomBytes(byteCount); return bytes