|
|
|
@ -119,19 +119,23 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
// unspecced consent tracking
|
|
|
|
|
if cfg.Matrix.UserConsentOptions.Enabled() {
|
|
|
|
|
consentAPIMux.HandleFunc("/consent", consent(userAPI, cfg)).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
consentAPIMux.Handle("/consent",
|
|
|
|
|
httputil.MakeHTMLAPI("consent", func(writer http.ResponseWriter, request *http.Request) *util.JSONResponse {
|
|
|
|
|
return consent(writer, request, userAPI, cfg)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
|
|
|
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/createRoom",
|
|
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return CreateRoom(req, device, cfg, accountDB, rsAPI, asAPI)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/join/{roomIDOrAlias}",
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -147,7 +151,7 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
if mscCfg.Enabled("msc2753") {
|
|
|
|
|
r0mux.Handle("/peek/{roomIDOrAlias}",
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -162,12 +166,12 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
}
|
|
|
|
|
r0mux.Handle("/joined_rooms",
|
|
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return GetJoinedRooms(req, device, rsAPI)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/join",
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -181,7 +185,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/leave",
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -195,7 +199,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/unpeek",
|
|
|
|
|
httputil.MakeAuthAPI("unpeek", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("unpeek", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -206,7 +210,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/ban",
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -215,7 +219,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/invite",
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -227,7 +231,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/kick",
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -236,7 +240,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/unban",
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("membership", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -245,7 +249,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/send/{eventType}",
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -254,7 +258,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -265,7 +269,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/event/{eventID}",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_get_event", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_get_event", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -274,7 +278,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -282,7 +286,7 @@ func Setup(
|
|
|
|
|
return OnIncomingStateRequest(req.Context(), device, rsAPI, vars["roomID"])
|
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -290,7 +294,7 @@ func Setup(
|
|
|
|
|
return GetAliases(req, rsAPI, device, vars["roomID"])
|
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -301,7 +305,7 @@ func Setup(
|
|
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat)
|
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -311,7 +315,7 @@ func Setup(
|
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -323,7 +327,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -358,7 +362,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
|
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -368,7 +372,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/directory/room/{roomAlias}",
|
|
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -387,7 +391,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
// TODO: Add AS support
|
|
|
|
|
r0mux.Handle("/directory/list/room/{roomID}",
|
|
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -402,19 +406,19 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/logout",
|
|
|
|
|
httputil.MakeAuthAPI("logout", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("logout", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return Logout(req, userAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/logout/all",
|
|
|
|
|
httputil.MakeAuthAPI("logout", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("logout", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return LogoutAll(req, userAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/typing/{userID}",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -426,7 +430,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/redact/{eventID}",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -435,7 +439,7 @@ func Setup(
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -445,7 +449,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/sendToDevice/{eventType}/{txnID}",
|
|
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -459,7 +463,7 @@ func Setup(
|
|
|
|
|
// rather than r0. It's an exact duplicate of the above handler.
|
|
|
|
|
// TODO: Remove this if/when sytest is fixed!
|
|
|
|
|
unstableMux.Handle("/sendToDevice/{eventType}/{txnID}",
|
|
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -470,7 +474,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/account/whoami",
|
|
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -479,7 +483,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/account/password",
|
|
|
|
|
httputil.MakeAuthAPI("password", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("password", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -488,7 +492,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/account/deactivate",
|
|
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -556,7 +560,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/avatar_url",
|
|
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -581,7 +585,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/profile/{userID}/displayname",
|
|
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -596,19 +600,19 @@ func Setup(
|
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/account/3pid",
|
|
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return GetAssociated3PIDs(req, accountDB, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/account/3pid",
|
|
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return CheckAndSave3PIDAssociation(req, accountDB, device, cfg)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
unstableMux.Handle("/account/3pid/delete",
|
|
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return Forget3PID(req, accountDB)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
@ -634,7 +638,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/voip/turnServer",
|
|
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -663,7 +667,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -673,7 +677,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -683,7 +687,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/account_data/{type}",
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -693,7 +697,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -703,7 +707,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/admin/whois/{userID}",
|
|
|
|
|
httputil.MakeAuthAPI("admin_whois", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("admin_whois", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -713,7 +717,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userID}/openid/request_token",
|
|
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -726,7 +730,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user_directory/search",
|
|
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -751,7 +755,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/members",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -761,7 +765,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/joined_members",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -771,7 +775,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/read_markers",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_read_markers", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_read_markers", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -784,7 +788,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/rooms/{roomID}/forget",
|
|
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -797,13 +801,13 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/devices",
|
|
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return GetDevicesByLocalpart(req, userAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
|
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -813,7 +817,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
|
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -823,7 +827,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/devices/{deviceID}",
|
|
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -833,7 +837,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/delete_devices",
|
|
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return DeleteDevices(req, userAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
@ -858,7 +862,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
|
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -868,7 +872,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
|
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -878,7 +882,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
|
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -888,7 +892,7 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
r0mux.Handle("/capabilities",
|
|
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
@ -898,7 +902,7 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
// Key Backup Versions (Metadata)
|
|
|
|
|
|
|
|
|
|
getBackupKeysVersion := httputil.MakeAuthAPI("get_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
getBackupKeysVersion := httputil.MakeAuthAPI("get_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -906,11 +910,11 @@ func Setup(
|
|
|
|
|
return KeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getLatestBackupKeysVersion := httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
getLatestBackupKeysVersion := httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
putBackupKeysVersion := httputil.MakeAuthAPI("put_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
putBackupKeysVersion := httputil.MakeAuthAPI("put_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -918,7 +922,7 @@ func Setup(
|
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, vars["version"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
deleteBackupKeysVersion := httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
deleteBackupKeysVersion := httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -926,7 +930,7 @@ func Setup(
|
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
postNewBackupKeysVersion := httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
postNewBackupKeysVersion := httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
@ -945,7 +949,7 @@ func Setup(
|
|
|
|
|
// Inserting E2E Backup Keys
|
|
|
|
|
|
|
|
|
|
// Bulk room and session
|
|
|
|
|
putBackupKeys := httputil.MakeAuthAPI("put_backup_keys", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
putBackupKeys := httputil.MakeAuthAPI("put_backup_keys", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
|
if version == "" {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
@ -962,7 +966,7 @@ func Setup(
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Single room bulk session
|
|
|
|
|
putBackupKeysRoom := httputil.MakeAuthAPI("put_backup_keys_room", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
putBackupKeysRoom := httputil.MakeAuthAPI("put_backup_keys_room", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -994,7 +998,7 @@ func Setup(
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Single room, single session
|
|
|
|
|
putBackupKeysRoomSession := httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
putBackupKeysRoomSession := httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -1036,11 +1040,11 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
// Querying E2E Backup Keys
|
|
|
|
|
|
|
|
|
|
getBackupKeys := httputil.MakeAuthAPI("get_backup_keys", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
getBackupKeys := httputil.MakeAuthAPI("get_backup_keys", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), "", "")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getBackupKeysRoom := httputil.MakeAuthAPI("get_backup_keys_room", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
getBackupKeysRoom := httputil.MakeAuthAPI("get_backup_keys_room", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -1048,7 +1052,7 @@ func Setup(
|
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], "")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getBackupKeysRoomSession := httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
getBackupKeysRoomSession := httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
@ -1068,11 +1072,11 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
// Cross-signing device keys
|
|
|
|
|
|
|
|
|
|
postDeviceSigningKeys := httputil.MakeAuthAPI("post_device_signing_keys", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
postDeviceSigningKeys := httputil.MakeAuthAPI("post_device_signing_keys", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return UploadCrossSigningDeviceKeys(req, userInteractiveAuth, keyAPI, device, accountDB, cfg)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
postDeviceSigningSignatures := httputil.MakeAuthAPI("post_device_signing_signatures", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
postDeviceSigningSignatures := httputil.MakeAuthAPI("post_device_signing_signatures", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return UploadCrossSigningDeviceSignatures(req, keyAPI, device)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
@ -1084,27 +1088,27 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
// Supplying a device ID is deprecated.
|
|
|
|
|
r0mux.Handle("/keys/upload/{deviceID}",
|
|
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return UploadKeys(req, keyAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/keys/upload",
|
|
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return UploadKeys(req, keyAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/keys/query",
|
|
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return QueryKeys(req, keyAPI, device)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/keys/claim",
|
|
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, cfg.Matrix.UserConsentOptions, false, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
return ClaimKeys(req, keyAPI)
|
|
|
|
|
}),
|
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
r0mux.Handle("/rooms/{roomId}/receipt/{receiptType}/{eventId}",
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, cfg.Matrix.UserConsentOptions, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, cfg.Matrix.UserConsentOptions, true, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
|
return *r
|
|
|
|
|
}
|
|
|
|
|