mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 19:33:09 -06:00
Authenticate user while fetching rooms from other server
This commit is contained in:
parent
cc972a8b94
commit
6ff9882931
|
|
@ -21,6 +21,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
|
|
@ -44,14 +46,19 @@ type filter struct {
|
|||
// GetPostPublicRooms implements GET and POST /publicRooms
|
||||
func GetPostPublicRooms(
|
||||
req *http.Request, cfg *config.Dendrite, server gomatrixserverlib.ServerName,
|
||||
publicRoomDatabase storage.Database, fedClient *gomatrixserverlib.FederationClient,
|
||||
publicRoomDatabase storage.Database, fedClient *gomatrixserverlib.FederationClient, data auth.Data,
|
||||
) util.JSONResponse {
|
||||
var request PublicRoomReq
|
||||
if fillErr := fillPublicRoomsReq(req, &request); fillErr != nil {
|
||||
return *fillErr
|
||||
}
|
||||
if server != "" && server != cfg.Matrix.ServerName {
|
||||
//TODO Authenticate user before serving rooms from other server
|
||||
// We require requests to be authenticated in order
|
||||
// to serve public rooms from other server
|
||||
_, jsonerr := auth.VerifyUserFromRequest(req, data)
|
||||
if jsonerr != nil {
|
||||
return *jsonerr
|
||||
}
|
||||
fres, err := fedClient.GetPublicRooms(req.Context(), server, int(request.Limit),
|
||||
request.Since, false, "")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -75,14 +75,14 @@ func Setup(
|
|||
return directory.GetPostPublicRoomsWithExternal(req, publicRoomsDB, fedClient, extRoomsProvider)
|
||||
}
|
||||
server := gomatrixserverlib.ServerName(req.URL.Query().Get("server"))
|
||||
return directory.GetPostPublicRooms(req, cfg, server, publicRoomsDB, fedClient)
|
||||
return directory.GetPostPublicRooms(req, cfg, server, publicRoomsDB, fedClient, authData)
|
||||
}),
|
||||
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
||||
|
||||
// Federation - TODO: should this live here or in federation API? It's sure easier if it's here so here it is.
|
||||
apiMux.Handle("/_matrix/federation/v1/publicRooms",
|
||||
common.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse {
|
||||
return directory.GetPostPublicRooms(req, cfg, cfg.Matrix.ServerName, publicRoomsDB, fedClient)
|
||||
return directory.GetPostPublicRooms(req, cfg, cfg.Matrix.ServerName, publicRoomsDB, fedClient, authData)
|
||||
}),
|
||||
).Methods(http.MethodGet)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue