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

Commit

Permalink
Revert "Support refresh tokens (#7802)"
Browse files Browse the repository at this point in the history
This reverts commit 8395934.
  • Loading branch information
turt2live authored Feb 16, 2022
1 parent 81f5228 commit aba61fa
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 504 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"glob-to-regexp": "^0.4.1",
"highlight.js": "^11.3.1",
"html-entities": "^1.4.0",
"idb-mutex": "^0.11.0",
"is-ip": "^3.1.0",
"jszip": "^3.7.0",
"katex": "^0.12.0",
Expand Down
242 changes: 23 additions & 219 deletions src/Lifecycle.ts

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions src/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { logger } from "matrix-js-sdk/src/logger";

import { IMatrixClientCreds } from "./MatrixClientPeg";
import SecurityCustomisations from "./customisations/Security";
import { TokenLifecycle } from "./TokenLifecycle";

interface ILoginOptions {
defaultDeviceDisplayName?: string;
Expand Down Expand Up @@ -65,11 +64,6 @@ interface ILoginParams {
token?: string;
device_id?: string;
initial_device_display_name?: string;

// If true, a refresh token will be requested. If the server supports it, it
// will be returned. Does nothing out of the ordinary if not set, false, or
// the server doesn't support the feature.
refresh_token?: boolean;
}
/* eslint-enable camelcase */

Expand Down Expand Up @@ -168,7 +162,6 @@ export default class Login {
password,
identifier,
initial_device_display_name: this.defaultDeviceDisplayName,
refresh_token: TokenLifecycle.instance.isFeasible,
};

const tryFallbackHs = (originalError) => {
Expand Down Expand Up @@ -242,9 +235,6 @@ export async function sendLoginRequest(
userId: data.user_id,
deviceId: data.device_id,
accessToken: data.access_token,
// Use the browser's local time for expiration timestamp - see TokenLifecycle for more info
accessTokenExpiryTs: data.expires_in_ms ? (data.expires_in_ms + Date.now()) : null,
accessTokenRefreshToken: data.refresh_token,
};

SecurityCustomisations.examineLoginResponse?.(data, creds);
Expand Down
27 changes: 0 additions & 27 deletions src/MatrixClientPeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export interface IMatrixClientCreds {
userId: string;
deviceId?: string;
accessToken: string;
accessTokenExpiryTs?: number; // set if access token expires
accessTokenRefreshToken?: string; // set if access token can be renewed
guest?: boolean;
pickleKey?: string;
freshLogin?: boolean;
Expand Down Expand Up @@ -101,14 +99,6 @@ export interface IMatrixClientPeg {
* @param {IMatrixClientCreds} creds The new credentials to use.
*/
replaceUsingCreds(creds: IMatrixClientCreds): void;

/**
* Similar to replaceUsingCreds(), but without the replacement operation.
* Credentials that can be updated in-place will be updated. All others
* will be ignored.
* @param {IMatrixClientCreds} creds The new credentials to use.
*/
updateUsingCreds(creds: IMatrixClientCreds): void;
}

/**
Expand Down Expand Up @@ -174,15 +164,6 @@ class MatrixClientPegClass implements IMatrixClientPeg {
this.createClient(creds);
}

public updateUsingCreds(creds: IMatrixClientCreds): void {
if (creds?.accessToken) {
this.currentClientCreds = creds;
this.matrixClient.setAccessToken(creds.accessToken);
} else {
// ignore, per signature
}
}

public async assign(): Promise<any> {
for (const dbType of ['indexeddb', 'memory']) {
try {
Expand Down Expand Up @@ -252,15 +233,7 @@ class MatrixClientPegClass implements IMatrixClientPeg {
}

public getCredentials(): IMatrixClientCreds {
let copiedCredentials = this.currentClientCreds;
if (this.currentClientCreds?.userId !== this.matrixClient?.credentials?.userId) {
// cached credentials belong to a different user - don't use them
copiedCredentials = null;
}
return {
// Copy the cached credentials before overriding what we can.
...(copiedCredentials ?? {}),

homeserverUrl: this.matrixClient.baseUrl,
identityServerUrl: this.matrixClient.idBaseUrl,
userId: this.matrixClient.credentials.userId,
Expand Down
233 changes: 0 additions & 233 deletions src/TokenLifecycle.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/structures/auth/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import AuthBody from "../../views/auth/AuthBody";
import AuthHeader from "../../views/auth/AuthHeader";
import InteractiveAuth from "../InteractiveAuth";
import Spinner from "../../views/elements/Spinner";
import { TokenLifecycle } from "../../../TokenLifecycle";

interface IProps {
serverConfig: ValidatedServerConfig;
Expand Down Expand Up @@ -416,7 +415,6 @@ export default class Registration extends React.Component<IProps, IState> {
initial_device_display_name: this.props.defaultDeviceDisplayName,
auth: undefined,
inhibit_login: undefined,
refresh_token: TokenLifecycle.instance.isFeasible,
};
if (auth) registerParams.auth = auth;
if (inhibitLogin !== undefined && inhibitLogin !== null) registerParams.inhibit_login = inhibitLogin;
Expand Down
3 changes: 0 additions & 3 deletions src/components/structures/auth/SoftLogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import AccessibleButton from '../../views/elements/AccessibleButton';
import Spinner from "../../views/elements/Spinner";
import AuthHeader from "../../views/auth/AuthHeader";
import AuthBody from "../../views/auth/AuthBody";
import { TokenLifecycle } from "../../../TokenLifecycle";

const LOGIN_VIEW = {
LOADING: 1,
Expand Down Expand Up @@ -155,7 +154,6 @@ export default class SoftLogout extends React.Component<IProps, IState> {
},
password: this.state.password,
device_id: MatrixClientPeg.get().getDeviceId(),
refresh_token: TokenLifecycle.instance.isFeasible,
};

let credentials = null;
Expand Down Expand Up @@ -189,7 +187,6 @@ export default class SoftLogout extends React.Component<IProps, IState> {
const loginParams = {
token: this.props.realQueryParams['loginToken'],
device_id: MatrixClientPeg.get().getDeviceId(),
refresh_token: TokenLifecycle.instance.isFeasible,
};

let credentials = null;
Expand Down
6 changes: 2 additions & 4 deletions src/utils/StorageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ const localStorage = window.localStorage;

// just *accessing* indexedDB throws an exception in firefox with
// indexeddb disabled.
let indexedDB: IDBFactory;
let indexedDB;
try {
indexedDB = window.indexedDB;
} catch (e) {}

export const IDB_SUPPORTED = !!indexedDB;

// The JS SDK will add a prefix of "matrix-js-sdk:" to the sync store name.
const SYNC_STORE_NAME = "riot-web-sync";
const CRYPTO_STORE_NAME = "matrix-js-sdk:crypto";
Expand Down Expand Up @@ -199,7 +197,7 @@ export function setCryptoInitialised(cryptoInited) {
/* Simple wrapper functions around IndexedDB.
*/

let idb: IDBDatabase = null;
let idb = null;

async function idbInit(): Promise<void> {
if (!indexedDB) {
Expand Down
Loading

0 comments on commit aba61fa

Please sign in to comment.