From b0955b532bd3cb5e3faae99d8a05ad65f42607b9 Mon Sep 17 00:00:00 2001 From: danielaloni Date: Mon, 12 Sep 2022 13:53:46 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Introduced=20/login=20I?= =?UTF-8?q?nhibitDevice=20for=202FA=20Initial=20Login=20Phase.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clientapi/auth/login.go | 10 ++++++---- clientapi/auth/password.go | 8 +++++--- clientapi/auth/user_interactive.go | 1 + clientapi/routing/login.go | 11 +++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/clientapi/auth/login.go b/clientapi/auth/login.go index fbae6f792..5a88295a3 100644 --- a/clientapi/auth/login.go +++ b/clientapi/auth/login.go @@ -44,7 +44,8 @@ func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.C } var header struct { - Type string `json:"type"` + Type string `json:"type"` + InhibitDevice bool `json:"inhibit_device"` } if err := json.Unmarshal(reqBytes, &header); err != nil { err := &util.JSONResponse{ @@ -58,9 +59,10 @@ func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.C switch header.Type { case authtypes.LoginTypePassword: typ = &LoginTypePassword{ - UserApi: useraccountAPI, - Config: cfg, - Rt: rt, + UserApi: useraccountAPI, + Config: cfg, + Rt: rt, + InhibitDevice: header.InhibitDevice, } case authtypes.LoginTypeToken: typ = &LoginTypeToken{ diff --git a/clientapi/auth/password.go b/clientapi/auth/password.go index 54019a8a8..a3e156fb7 100644 --- a/clientapi/auth/password.go +++ b/clientapi/auth/password.go @@ -42,9 +42,10 @@ const email = "email" // LoginTypePassword implements https://matrix.org/docs/spec/client_server/r0.6.1#password-based type LoginTypePassword struct { - UserApi api.ClientUserAPI - Config *config.ClientAPI - Rt *ratelimit.RtFailedLogin + UserApi api.ClientUserAPI + Config *config.ClientAPI + Rt *ratelimit.RtFailedLogin + InhibitDevice bool } func (t *LoginTypePassword) Name() string { @@ -61,6 +62,7 @@ func (t *LoginTypePassword) LoginFromJSON(ctx context.Context, reqBytes []byte) if err != nil { return nil, nil, err } + login.InhibitDevice = t.InhibitDevice return login, func(context.Context, *util.JSONResponse) {}, nil } diff --git a/clientapi/auth/user_interactive.go b/clientapi/auth/user_interactive.go index 3b2473ea2..68921e1c7 100644 --- a/clientapi/auth/user_interactive.go +++ b/clientapi/auth/user_interactive.go @@ -66,6 +66,7 @@ type LoginIdentifier struct { type Login struct { LoginIdentifier // Flat fields deprecated in favour of `identifier`. Identifier LoginIdentifier `json:"identifier"` + InhibitDevice bool `json:"inhibit_device,omitempty"` // Both DeviceID and InitialDisplayName can be omitted, or empty strings ("") // Thus a pointer is needed to differentiate between the two diff --git a/clientapi/routing/login.go b/clientapi/routing/login.go index cae24ce96..0105f6d21 100644 --- a/clientapi/routing/login.go +++ b/clientapi/routing/login.go @@ -69,6 +69,17 @@ func Login( if authErr != nil { return *authErr } + if login.InhibitDevice { + return util.JSONResponse{ + Code: http.StatusOK, + JSON: loginResponse{ + UserID: login.Username(), + AccessToken: "", + HomeServer: cfg.Matrix.ServerName, + DeviceID: "", + }, + } + } // make a device/access token authErr2 := completeAuth(req.Context(), cfg.Matrix.ServerName, userAPI, login, req.RemoteAddr, req.UserAgent()) cleanup(req.Context(), &authErr2)