You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Improve types around login, registration, UIA and identity servers (#3537)
This commit is contained in:
committed by
GitHub
parent
89cabc4912
commit
1c1ac137d3
124
src/client.ts
124
src/client.ts
@@ -101,7 +101,7 @@ import {
|
||||
import { IIdentityServerProvider } from "./@types/IIdentityServerProvider";
|
||||
import { MatrixScheduler } from "./scheduler";
|
||||
import { BeaconEvent, BeaconEventHandlerMap } from "./models/beacon";
|
||||
import { IAuthData, IAuthDict } from "./interactive-auth";
|
||||
import { AuthDict } from "./interactive-auth";
|
||||
import { IMinimalEvent, IRoomEvent, IStateEvent } from "./sync-accumulator";
|
||||
import { CrossSigningKey, ICreateSecretStorageOpts, IEncryptedEventInfo, IRecoveryKey } from "./crypto/api";
|
||||
import { EventTimelineSet } from "./models/event-timeline-set";
|
||||
@@ -178,7 +178,14 @@ import { IThreepid } from "./@types/threepids";
|
||||
import { CryptoStore, OutgoingRoomKeyRequest } from "./crypto/store/base";
|
||||
import { GroupCall, IGroupCallDataChannelOptions, GroupCallIntent, GroupCallType } from "./webrtc/groupCall";
|
||||
import { MediaHandler } from "./webrtc/mediaHandler";
|
||||
import { LoginTokenPostResponse, ILoginFlowsResponse, IRefreshTokenResponse, SSOAction } from "./@types/auth";
|
||||
import {
|
||||
LoginTokenPostResponse,
|
||||
ILoginFlowsResponse,
|
||||
IRefreshTokenResponse,
|
||||
SSOAction,
|
||||
LoginResponse,
|
||||
LoginRequest,
|
||||
} from "./@types/auth";
|
||||
import { TypedEventEmitter } from "./models/typed-event-emitter";
|
||||
import { MAIN_ROOM_TIMELINE, ReceiptType } from "./@types/read_receipts";
|
||||
import { MSC3575SlidingSyncRequest, MSC3575SlidingSyncResponse, SlidingSync } from "./sliding-sync";
|
||||
@@ -209,6 +216,7 @@ import {
|
||||
ServerSideSecretStorage,
|
||||
ServerSideSecretStorageImpl,
|
||||
} from "./secret-storage";
|
||||
import { RegisterRequest, RegisterResponse } from "./@types/registration";
|
||||
|
||||
export type Store = IStore;
|
||||
|
||||
@@ -717,18 +725,8 @@ interface IJoinedMembersResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export interface IRegisterRequestParams {
|
||||
auth?: IAuthDict;
|
||||
username?: string;
|
||||
password?: string;
|
||||
refresh_token?: boolean;
|
||||
guest_access_token?: string;
|
||||
x_show_msisdn?: boolean;
|
||||
bind_msisdn?: boolean;
|
||||
bind_email?: boolean;
|
||||
inhibit_login?: boolean;
|
||||
initial_device_display_name?: string;
|
||||
}
|
||||
// Re-export for backwards compatibility
|
||||
export type IRegisterRequestParams = RegisterRequest;
|
||||
|
||||
export interface IPublicRoomsChunkRoom {
|
||||
room_id: string;
|
||||
@@ -7653,7 +7651,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @param bindThreepids - Set key 'email' to true to bind any email
|
||||
* threepid uses during registration in the identity server. Set 'msisdn' to
|
||||
* true to bind msisdn.
|
||||
* @returns Promise which resolves: TODO
|
||||
* @returns Promise which resolves to a RegisterResponse object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public register(
|
||||
@@ -7664,7 +7662,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
bindThreepids?: boolean | null | { email?: boolean; msisdn?: boolean },
|
||||
guestAccessToken?: string,
|
||||
inhibitLogin?: boolean,
|
||||
): Promise<IAuthData> {
|
||||
): Promise<RegisterResponse> {
|
||||
// backwards compat
|
||||
if (bindThreepids === true) {
|
||||
bindThreepids = { email: true };
|
||||
@@ -7675,7 +7673,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
auth.session = sessionId;
|
||||
}
|
||||
|
||||
const params: IRegisterRequestParams = {
|
||||
const params: RegisterRequest = {
|
||||
auth: auth,
|
||||
refresh_token: true, // always ask for a refresh token - does nothing if unsupported
|
||||
};
|
||||
@@ -7731,8 +7729,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* `{ user_id, device_id, access_token, home_server }`
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public registerGuest({ body }: { body?: any } = {}): Promise<any> {
|
||||
// TODO: Types
|
||||
public registerGuest({ body }: { body?: RegisterRequest } = {}): Promise<RegisterResponse> {
|
||||
return this.registerRequest(body || {}, "guest");
|
||||
}
|
||||
|
||||
@@ -7742,7 +7739,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: to the /register response
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public registerRequest(data: IRegisterRequestParams, kind?: string): Promise<IAuthData> {
|
||||
public registerRequest(data: RegisterRequest, kind?: string): Promise<RegisterResponse> {
|
||||
const params: { kind?: string } = {};
|
||||
if (kind) {
|
||||
params.kind = kind;
|
||||
@@ -7795,23 +7792,15 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Promise which resolves: TODO
|
||||
* @returns Promise which resolves to a LoginResponse object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public login(loginType: string, data: any): Promise<any> {
|
||||
// TODO: Types
|
||||
const loginData = {
|
||||
type: loginType,
|
||||
};
|
||||
|
||||
// merge data into loginData
|
||||
Object.assign(loginData, data);
|
||||
|
||||
public login(loginType: LoginRequest["type"], data: Omit<LoginRequest, "type">): Promise<LoginResponse> {
|
||||
return this.http
|
||||
.authedRequest<{
|
||||
access_token?: string;
|
||||
user_id?: string;
|
||||
}>(Method.Post, "/login", undefined, loginData)
|
||||
.authedRequest<LoginResponse>(Method.Post, "/login", undefined, {
|
||||
...data,
|
||||
type: loginType,
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.access_token && response.user_id) {
|
||||
this.http.opts.accessToken = response.access_token;
|
||||
@@ -7824,11 +7813,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Promise which resolves: TODO
|
||||
* @returns Promise which resolves to a LoginResponse object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public loginWithPassword(user: string, password: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public loginWithPassword(user: string, password: string): Promise<LoginResponse> {
|
||||
return this.login("m.login.password", {
|
||||
user: user,
|
||||
password: password,
|
||||
@@ -7837,11 +7825,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
|
||||
/**
|
||||
* @param relayState - URL Callback after SAML2 Authentication
|
||||
* @returns Promise which resolves: TODO
|
||||
* @returns Promise which resolves to a LoginResponse object
|
||||
* @returns Rejects: with an error response.
|
||||
* @deprecated this isn't in the Matrix spec anymore
|
||||
*/
|
||||
public loginWithSAML2(relayState: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public loginWithSAML2(relayState: string): Promise<LoginResponse> {
|
||||
return this.login("m.login.saml2", {
|
||||
relay_state: relayState,
|
||||
});
|
||||
@@ -7881,11 +7869,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
|
||||
/**
|
||||
* @param token - Login token previously received from homeserver
|
||||
* @returns Promise which resolves: TODO
|
||||
* @returns Promise which resolves to a LoginResponse object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public loginWithToken(token: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public loginWithToken(token: string): Promise<LoginResponse> {
|
||||
return this.login("m.login.token", {
|
||||
token: token,
|
||||
});
|
||||
@@ -7929,7 +7916,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* to false.
|
||||
* @returns Promise which resolves: On success, the empty object
|
||||
*/
|
||||
public deactivateAccount(auth?: any, erase?: boolean): Promise<{}> {
|
||||
public deactivateAccount(auth?: any, erase?: boolean): Promise<{ id_server_unbind_result: IdServerUnbindResult }> {
|
||||
const body: any = {};
|
||||
if (auth) {
|
||||
body.auth = auth;
|
||||
@@ -7950,7 +7937,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: On success, the token response
|
||||
* or UIA auth data.
|
||||
*/
|
||||
public async requestLoginToken(auth?: IAuthDict): Promise<UIAResponse<LoginTokenPostResponse>> {
|
||||
public async requestLoginToken(auth?: AuthDict): Promise<UIAResponse<LoginTokenPostResponse>> {
|
||||
// use capabilities to determine which revision of the MSC is being used
|
||||
const capabilities = await this.getCapabilities();
|
||||
// use r1 endpoint if capability is exposed otherwise use old r0 endpoint
|
||||
@@ -8590,7 +8577,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: to an empty object `{}`
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public setPassword(authDict: IAuthDict, newPassword: string, logoutDevices?: boolean): Promise<{}> {
|
||||
public setPassword(authDict: AuthDict, newPassword: string, logoutDevices?: boolean): Promise<{}> {
|
||||
const path = "/account/password";
|
||||
const data = {
|
||||
auth: authDict,
|
||||
@@ -8648,7 +8635,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: result object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public deleteDevice(deviceId: string, auth?: IAuthDict): Promise<IAuthData | {}> {
|
||||
public deleteDevice(deviceId: string, auth?: AuthDict): Promise<{}> {
|
||||
const path = utils.encodeUri("/devices/$device_id", {
|
||||
$device_id: deviceId,
|
||||
});
|
||||
@@ -8670,7 +8657,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: result object
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public deleteMultipleDevices(devices: string[], auth?: IAuthDict): Promise<IAuthData | {}> {
|
||||
public deleteMultipleDevices(devices: string[], auth?: AuthDict): Promise<{}> {
|
||||
const body: any = { devices };
|
||||
|
||||
if (auth) {
|
||||
@@ -8955,7 +8942,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
return this.http.authedRequest(Method.Get, "/keys/changes", qps);
|
||||
}
|
||||
|
||||
public uploadDeviceSigningKeys(auth?: IAuthDict, keys?: CrossSigningKeys): Promise<{}> {
|
||||
public uploadDeviceSigningKeys(auth?: AuthDict, keys?: CrossSigningKeys): Promise<{}> {
|
||||
// API returns empty object
|
||||
const data = Object.assign({}, keys);
|
||||
if (auth) Object.assign(data, { auth });
|
||||
@@ -9168,8 +9155,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @param identityAccessToken - The access token for the identity server.
|
||||
* @returns The hashing information for the identity server.
|
||||
*/
|
||||
public getIdentityHashDetails(identityAccessToken: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public getIdentityHashDetails(identityAccessToken: string): Promise<{
|
||||
/**
|
||||
* The algorithms the server supports. Must contain at least sha256.
|
||||
*/
|
||||
algorithms: string[];
|
||||
/**
|
||||
* The pepper the client MUST use in hashing identifiers,
|
||||
* and MUST supply to the /lookup endpoint when performing lookups.
|
||||
*/
|
||||
lookup_pepper: string;
|
||||
}> {
|
||||
return this.http.idServerRequest(
|
||||
Method.Get,
|
||||
"/hash_details",
|
||||
@@ -9277,8 +9273,18 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* exists
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public async lookupThreePid(medium: string, address: string, identityAccessToken: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public async lookupThreePid(
|
||||
medium: string,
|
||||
address: string,
|
||||
identityAccessToken: string,
|
||||
): Promise<
|
||||
| {
|
||||
address: string;
|
||||
medium: string;
|
||||
mxid: string;
|
||||
}
|
||||
| {}
|
||||
> {
|
||||
// Note: we're using the V2 API by calling this function, but our
|
||||
// function contract requires a V1 response. We therefore have to
|
||||
// convert it manually.
|
||||
@@ -9314,8 +9320,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: Lookup results from IS.
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public async bulkLookupThreePids(query: [string, string][], identityAccessToken: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public async bulkLookupThreePids(
|
||||
query: [string, string][],
|
||||
identityAccessToken: string,
|
||||
): Promise<{
|
||||
threepids: [medium: string, address: string, mxid: string][];
|
||||
}> {
|
||||
// Note: we're using the V2 API by calling this function, but our
|
||||
// function contract requires a V1 response. We therefore have to
|
||||
// convert it manually.
|
||||
@@ -9353,8 +9363,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves: an object with account info.
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public getIdentityAccount(identityAccessToken: string): Promise<any> {
|
||||
// TODO: Types
|
||||
public getIdentityAccount(identityAccessToken: string): Promise<{ user_id: string }> {
|
||||
return this.http.idServerRequest(Method.Get, "/account", undefined, IdentityPrefix.V2, identityAccessToken);
|
||||
}
|
||||
|
||||
@@ -9447,7 +9456,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns Promise which resolves to the result object
|
||||
*/
|
||||
public getThirdpartyUser(protocol: string, params: any): Promise<IThirdPartyUser[]> {
|
||||
// TODO: Types
|
||||
const path = utils.encodeUri("/thirdparty/user/$protocol", {
|
||||
$protocol: protocol,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user