Skip to content

Commit 583e480

Browse files
hughnsduxovni
andauthored
Add login flow types from matrix-react-sdk (#2633)
Co-authored-by: Faye Duxovni <fayed@element.io>
1 parent b22c671 commit 583e480

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/@types/auth.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,58 @@ export interface IRefreshTokenResponse {
2727
}
2828

2929
/* eslint-enable camelcase */
30+
31+
/**
32+
* Response to GET login flows as per https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3login
33+
*/
34+
export interface ILoginFlowsResponse {
35+
flows: LoginFlow[];
36+
}
37+
38+
export type LoginFlow = ISSOFlow | IPasswordFlow | ILoginFlow;
39+
40+
export interface ILoginFlow {
41+
type: string;
42+
}
43+
44+
export interface IPasswordFlow extends ILoginFlow {
45+
type: "m.login.password";
46+
}
47+
48+
/**
49+
* Representation of SSO flow as per https://spec.matrix.org/latest/client-server-api/#client-login-via-sso
50+
*/
51+
export interface ISSOFlow extends ILoginFlow {
52+
type: "m.login.sso" | "m.login.cas";
53+
// eslint-disable-next-line camelcase
54+
identity_providers?: IIdentityProvider[];
55+
}
56+
57+
export enum IdentityProviderBrand {
58+
Gitlab = "gitlab",
59+
Github = "github",
60+
Apple = "apple",
61+
Google = "google",
62+
Facebook = "facebook",
63+
Twitter = "twitter",
64+
}
65+
66+
export interface IIdentityProvider {
67+
id: string;
68+
name: string;
69+
icon?: string;
70+
brand?: IdentityProviderBrand | string;
71+
}
72+
73+
/**
74+
* Parameters to login request as per https://spec.matrix.org/latest/client-server-api/#login
75+
*/
76+
/* eslint-disable camelcase */
77+
export interface ILoginParams {
78+
identifier?: object;
79+
password?: string;
80+
token?: string;
81+
device_id?: string;
82+
initial_device_display_name?: string;
83+
}
84+
/* eslint-enable camelcase */

src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ import { IPusher, IPusherRequest, IPushRules, PushRuleAction, PushRuleKind, Rule
188188
import { IThreepid } from "./@types/threepids";
189189
import { CryptoStore } from "./crypto/store/base";
190190
import { MediaHandler } from "./webrtc/mediaHandler";
191-
import { IRefreshTokenResponse } from "./@types/auth";
191+
import { ILoginFlowsResponse, IRefreshTokenResponse } from "./@types/auth";
192192
import { TypedEventEmitter } from "./models/typed-event-emitter";
193193
import { ReceiptType } from "./@types/read_receipts";
194194
import { MSC3575SlidingSyncRequest, MSC3575SlidingSyncResponse, SlidingSync } from "./sliding-sync";
@@ -7077,10 +7077,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
70777077

70787078
/**
70797079
* @param {module:client.callback} callback Optional.
7080-
* @return {Promise} Resolves: TODO
7080+
* @return {Promise<ILoginFlowsResponse>} Resolves to the available login flows
70817081
* @return {module:http-api.MatrixError} Rejects: with an error response.
70827082
*/
7083-
public loginFlows(callback?: Callback): Promise<any> { // TODO: Types
7083+
public loginFlows(callback?: Callback): Promise<ILoginFlowsResponse> {
70847084
return this.http.request(callback, Method.Get, "/login");
70857085
}
70867086

0 commit comments

Comments
 (0)