From 7b8c12247c17071da209e87dc863bf8582bebd8f Mon Sep 17 00:00:00 2001 From: Anant Prakash Date: Thu, 26 Jul 2018 23:13:24 +0530 Subject: [PATCH] Trim code, update against merged changes --- .../dendrite/clientapi/routing/routing.go | 12 +++++----- .../dendrite/clientapi/routing/whoami.go | 22 +++++-------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index d3c238b21..0314861b0 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -181,6 +181,12 @@ func Setup( }), ).Methods(http.MethodPut, http.MethodOptions) + r0mux.Handle("/account/whoami", + common.MakeAuthAPI("whoami", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + return Whoami(req, device) + }), + ).Methods(http.MethodGet, http.MethodOptions) + // Stub endpoints required by Riot r0mux.Handle("/login", @@ -379,12 +385,6 @@ func Setup( }), ).Methods(http.MethodPut, http.MethodOptions) - r0mux.Handle("/account/whoami", - common.MakeAuthAPI("whoami", accountDB, deviceDB, cfg.Derived.ApplicationServices, func(req *http.Request, user string, device *authtypes.Device) util.JSONResponse { - return Whoami(req, user) - }), - ).Methods(http.MethodGet, http.MethodOptions) - // Stub implementations for sytest r0mux.Handle("/events", common.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse { diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/whoami.go b/src/github.com/matrix-org/dendrite/clientapi/routing/whoami.go index 4ece462a0..840bcb5f2 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/whoami.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/whoami.go @@ -15,7 +15,7 @@ package routing import ( "net/http" - "github.com/matrix-org/dendrite/clientapi/jsonerror" + "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/util" ) @@ -24,23 +24,11 @@ type whoamiResponse struct { UserID string `json:"user_id"` } -// Whoami implements `/account/whoami` which enables client to query owner of the HTTP request. +// Whoami implements `/account/whoami` which enables client to query their account user id. // https://matrix.org/docs/spec/client_server/r0.3.0.html#get-matrix-client-r0-account-whoami -func Whoami(req *http.Request, userID string) util.JSONResponse { - - if req.Method == http.MethodGet { - util.GetLogger(req.Context()).WithField("user", userID).Info("Processing whoami request") - - return util.JSONResponse{ - Code: http.StatusOK, - JSON: whoamiResponse{ - UserID: userID, - }, - } - } - +func Whoami(req *http.Request, device *authtypes.Device) util.JSONResponse { return util.JSONResponse{ - Code: http.StatusMethodNotAllowed, - JSON: jsonerror.NotFound("Bad method"), + Code: http.StatusOK, + JSON: whoamiResponse{UserID: device.UserID}, } }