Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4bc5990

Browse files
authored
Merge pull request #5755 from aaronraimist/warn-on-access-token-reveal
Warn on access token reveal
2 parents 2bf931b + 35c1e54 commit 4bc5990

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

res/css/views/settings/tabs/user/_HelpUserSettingsTab.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,34 @@ limitations under the License.
2222
.mx_HelpUserSettingsTab span.mx_AccessibleButton {
2323
word-break: break-word;
2424
}
25+
26+
.mx_HelpUserSettingsTab code {
27+
word-break: break-all;
28+
user-select: all;
29+
}
30+
31+
.mx_HelpUserSettingsTab_accessToken {
32+
display: flex;
33+
justify-content: space-between;
34+
border-radius: 5px;
35+
border: solid 1px $light-fg-color;
36+
margin-bottom: 10px;
37+
margin-top: 10px;
38+
padding: 10px;
39+
}
40+
41+
.mx_HelpUserSettingsTab_accessToken_copy {
42+
flex-shrink: 0;
43+
cursor: pointer;
44+
margin-left: 20px;
45+
display: inherit;
46+
}
47+
48+
.mx_HelpUserSettingsTab_accessToken_copy > div {
49+
mask-image: url($copy-button-url);
50+
background-color: $message-action-bar-fg-color;
51+
margin-left: 5px;
52+
width: 20px;
53+
height: 20px;
54+
background-repeat: no-repeat;
55+
}

src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import React from 'react';
1818
import {_t, getCurrentLanguage} from "../../../../../languageHandler";
1919
import {MatrixClientPeg} from "../../../../../MatrixClientPeg";
2020
import AccessibleButton from "../../../elements/AccessibleButton";
21+
import AccessibleTooltipButton from '../../../elements/AccessibleTooltipButton';
2122
import SdkConfig from "../../../../../SdkConfig";
2223
import createRoom from "../../../../../createRoom";
2324
import Modal from "../../../../../Modal";
@@ -26,6 +27,9 @@ import PlatformPeg from "../../../../../PlatformPeg";
2627
import * as KeyboardShortcuts from "../../../../../accessibility/KeyboardShortcuts";
2728
import UpdateCheckButton from "../../UpdateCheckButton";
2829
import { replaceableComponent } from "../../../../../utils/replaceableComponent";
30+
import { copyPlaintext } from "../../../../../utils/strings";
31+
import * as ContextMenu from "../../../../structures/ContextMenu";
32+
import { toRightOf } from "../../../../structures/ContextMenu";
2933

3034
interface IProps {
3135
closeSettingsFn: () => {};
@@ -38,6 +42,8 @@ interface IState {
3842

3943
@replaceableComponent("views.settings.tabs.user.HelpUserSettingsTab")
4044
export default class HelpUserSettingsTab extends React.Component<IProps, IState> {
45+
protected closeCopiedTooltip: () => void;
46+
4147
constructor(props) {
4248
super(props);
4349

@@ -56,6 +62,12 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
5662
});
5763
}
5864

65+
componentWillUnmount() {
66+
// if the Copied tooltip is open then get rid of it, there are ways to close the modal which wouldn't close
67+
// the tooltip otherwise, such as pressing Escape
68+
if (this.closeCopiedTooltip) this.closeCopiedTooltip();
69+
}
70+
5971
private onClearCacheAndReload = (e) => {
6072
if (!PlatformPeg.get()) return;
6173

@@ -153,6 +165,20 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
153165
);
154166
}
155167

168+
onAccessTokenCopyClick = async (e) => {
169+
e.preventDefault();
170+
const target = e.target; // copy target before we go async and React throws it away
171+
172+
const successful = await copyPlaintext(MatrixClientPeg.get().getAccessToken());
173+
const buttonRect = target.getBoundingClientRect();
174+
const GenericTextContextMenu = sdk.getComponent('context_menus.GenericTextContextMenu');
175+
const {close} = ContextMenu.createMenu(GenericTextContextMenu, {
176+
...toRightOf(buttonRect, 2),
177+
message: successful ? _t('Copied!') : _t('Failed to copy'),
178+
});
179+
this.closeCopiedTooltip = target.onmouseleave = close;
180+
}
181+
156182
render() {
157183
const brand = SdkConfig.get().brand;
158184

@@ -269,12 +295,20 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
269295
<div className='mx_SettingsTab_subsectionText'>
270296
{_t("Homeserver is")} <code>{MatrixClientPeg.get().getHomeserverUrl()}</code><br />
271297
{_t("Identity Server is")} <code>{MatrixClientPeg.get().getIdentityServerUrl()}</code><br />
272-
{_t("Access Token:") + ' '}
273-
<AccessibleButton element="span" onClick={this.showSpoiler}
274-
data-spoiler={MatrixClientPeg.get().getAccessToken()}
275-
>
276-
&lt;{ _t("click to reveal") }&gt;
277-
</AccessibleButton>
298+
<br />
299+
<details>
300+
<summary>{_t("Access Token")}</summary><br />
301+
<b>{_t("Your access token gives full access to your account."
302+
+ " Do not share it with anyone." )}</b>
303+
<div className="mx_HelpUserSettingsTab_accessToken">
304+
<code>{MatrixClientPeg.get().getAccessToken()}</code>
305+
<AccessibleTooltipButton
306+
title={_t("Copy")}
307+
onClick={this.onAccessTokenCopyClick}
308+
className="mx_HelpUserSettingsTab_accessToken_copy"
309+
/>
310+
</div>
311+
</details><br />
278312
<div className='mx_HelpUserSettingsTab_debugButton'>
279313
<AccessibleButton onClick={this.onClearCacheAndReload} kind='danger'>
280314
{_t("Clear cache and reload")}

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,9 @@
12521252
"olm version:": "olm version:",
12531253
"Homeserver is": "Homeserver is",
12541254
"Identity Server is": "Identity Server is",
1255-
"Access Token:": "Access Token:",
1256-
"click to reveal": "click to reveal",
1255+
"Access Token": "Access Token",
1256+
"Your access token gives full access to your account. Do not share it with anyone.": "Your access token gives full access to your account. Do not share it with anyone.",
1257+
"Copy": "Copy",
12571258
"Clear cache and reload": "Clear cache and reload",
12581259
"Labs": "Labs",
12591260
"Customise your experience with experimental labs features. <a>Learn more</a>.": "Customise your experience with experimental labs features. <a>Learn more</a>.",
@@ -2347,7 +2348,6 @@
23472348
"Share Community": "Share Community",
23482349
"Share Room Message": "Share Room Message",
23492350
"Link to selected message": "Link to selected message",
2350-
"Copy": "Copy",
23512351
"Command Help": "Command Help",
23522352
"Failed to save space settings.": "Failed to save space settings.",
23532353
"Space settings": "Space settings",

0 commit comments

Comments
 (0)