From b7c676cdf3ebeff54c3c16099a888697a2a46a8c Mon Sep 17 00:00:00 2001 From: mohitks Date: Sun, 15 Dec 2019 10:11:42 +0530 Subject: [PATCH] add identifier field to login Signed-off-by: mohitks --- clientapi/routing/login.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/clientapi/routing/login.go b/clientapi/routing/login.go index 02d958152..c1036a2bd 100644 --- a/clientapi/routing/login.go +++ b/clientapi/routing/login.go @@ -40,9 +40,14 @@ type flow struct { Stages []string `json:"stages"` } +type identifier struct { + Type string `json:"type"` + User string `json:"user"` +} type passwordRequest struct { - User string `json:"user"` - Password string `json:"password"` + User string `json:"user"` + Password string `json:"password"` + Identifier *identifier `json:"identifier"` // Both DeviceID and InitialDisplayName can be omitted, or empty strings ("") // Thus a pointer is needed to differentiate between the two InitialDisplayName *string `json:"initial_device_display_name"` @@ -79,6 +84,22 @@ func Login( if resErr != nil { return *resErr } + + if r.Identifier != nil { + // go over identifier types + switch r.Identifier.Type { + case "m.type.user": + // depreciate user in favor of identifier field + // https://matrix.org/docs/spec/client_server/unstable#post-matrix-client-r0-login + r.User = r.Identifier.User + default: + return util.JSONResponse{ + Code: http.StatusNotImplemented, + JSON: jsonerror.Unknown("unknown/unimplemented identifier type"), + } + } + } + if r.User == "" { return util.JSONResponse{ Code: http.StatusBadRequest,