mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
Logout upstream as well (best effort)
This commit is contained in:
parent
18ee47fa49
commit
c96366b647
@ -112,9 +112,13 @@ export default class AccountController {
|
|||||||
* @returns {Promise<*>} Resolves when complete.
|
* @returns {Promise<*>} Resolves when complete.
|
||||||
*/
|
*/
|
||||||
public async logout(user: IMSCUser): Promise<any> {
|
public async logout(user: IMSCUser): Promise<any> {
|
||||||
// TODO: Create a link to upstream tokens to log them out too
|
const tokens = await UserScalarToken.findAll({where: {scalarToken: user.token}, include: [Upstream]});
|
||||||
const tokens = await UserScalarToken.findAll({where: {scalarToken: user.token}});
|
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
|
if (token.upstream) {
|
||||||
|
LogService.info("AccountController", "Logging user out of upstream");
|
||||||
|
const client = new ScalarClient(token.upstream, ScalarClient.KIND_MATRIX_V1);
|
||||||
|
await client.logout(token.scalarToken);
|
||||||
|
}
|
||||||
await token.destroy();
|
await token.destroy();
|
||||||
}
|
}
|
||||||
Cache.for(CACHE_SCALAR_ACCOUNTS).clear();
|
Cache.for(CACHE_SCALAR_ACCOUNTS).clear();
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
AllowNull, AutoIncrement, BelongsTo, Column, ForeignKey, Model, PrimaryKey,
|
AllowNull,
|
||||||
|
AutoIncrement,
|
||||||
|
BelongsTo,
|
||||||
|
Column,
|
||||||
|
ForeignKey,
|
||||||
|
Model,
|
||||||
|
PrimaryKey,
|
||||||
Table
|
Table
|
||||||
} from "sequelize-typescript";
|
} from "sequelize-typescript";
|
||||||
import User from "./User";
|
import User from "./User";
|
||||||
@ -33,4 +39,7 @@ export default class UserScalarToken extends Model<UserScalarToken> {
|
|||||||
@Column
|
@Column
|
||||||
@ForeignKey(() => Upstream)
|
@ForeignKey(() => Upstream)
|
||||||
upstreamId?: number;
|
upstreamId?: number;
|
||||||
|
|
||||||
|
@BelongsTo(() => Upstream)
|
||||||
|
upstream: Upstream;
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ import * as request from "request";
|
|||||||
import { LogService } from "matrix-js-snippets";
|
import { LogService } from "matrix-js-snippets";
|
||||||
import Upstream from "../db/models/Upstream";
|
import Upstream from "../db/models/Upstream";
|
||||||
import { SCALAR_API_VERSION } from "../utils/common-constants";
|
import { SCALAR_API_VERSION } from "../utils/common-constants";
|
||||||
import * as url from "url";
|
|
||||||
|
|
||||||
const REGISTER_ROUTE = "/register";
|
const REGISTER_ROUTE = "/register";
|
||||||
const ACCOUNT_INFO_ROUTE = "/account";
|
const ACCOUNT_INFO_ROUTE = "/account";
|
||||||
@ -30,8 +29,8 @@ export class ScalarClient {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const parsed = url.parse(this.upstream.scalarUrl);
|
const parsed = new URL(this.upstream.scalarUrl);
|
||||||
parsed.path = '/_matrix/integrations/v1' + (path === ACCOUNT_INFO_ROUTE ? path : `${ACCOUNT_INFO_ROUTE}${path}`);
|
parsed.pathname = '/_matrix/integrations/v1' + (path === ACCOUNT_INFO_ROUTE ? path : `${ACCOUNT_INFO_ROUTE}${path}`);
|
||||||
|
|
||||||
const headers = {};
|
const headers = {};
|
||||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||||
@ -110,7 +109,7 @@ export class ScalarClient {
|
|||||||
LogService.error("ScalarClient", err);
|
LogService.error("ScalarClient", err);
|
||||||
reject(err);
|
reject(err);
|
||||||
} else if (res.statusCode !== 200) {
|
} else if (res.statusCode !== 200) {
|
||||||
LogService.error("ScalarClient", "Got status code " + res.statusCode + " while getting information for token");
|
LogService.error("ScalarClient", "Got status code " + res.statusCode + " while logging out token");
|
||||||
reject(res.statusCode);
|
reject(res.statusCode);
|
||||||
} else {
|
} else {
|
||||||
resolve(res.body);
|
resolve(res.body);
|
||||||
|
Loading…
Reference in New Issue
Block a user