Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/appservice/Appservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export interface IAppserviceRegistration {
*/
"de.sorunome.msc2409.push_ephemeral"?: boolean;

/**
* ** Experimental **
*
* Should the AS use the new device management APIs. Optional.
* @see https://github.com/matrix-org/matrix-spec-proposals/pull/4190
*/
"io.element.msc4190"?: boolean;

// not interested in other options
}

Expand Down
16 changes: 13 additions & 3 deletions src/appservice/Intent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { randomUUID } from "crypto";

import {
DeviceKeyAlgorithm,
extractRequestError,
Expand Down Expand Up @@ -162,9 +164,17 @@ export class Intent {
}

if (!prepared) {
// XXX: We work around servers that don't support device_id impersonation
const accessToken = await Promise.resolve(storage?.readValue("accessToken"));
if (!accessToken) {
let accessToken;
if (this.options.registration["io.element.msc4190"]) {
// Generate a random device ID and create it
deviceId = randomUUID();
// Make sure the device is registered
await this.client.doRequest("PUT", `/_matrix/client/v3/devices/${deviceId}`, null, {});
this.makeClient(true);
this.client.impersonateUserId(this.userId, deviceId);
prepared = true;
} else if (!(accessToken = await Promise.resolve(storage?.readValue("accessToken")))) {
// XXX: We work around servers that don't support device_id impersonation
const loginBody = {
type: "m.login.application_service",
identifier: {
Expand Down
Loading