Make userapi responsible for checking access tokens (#1133)

* Make userapi responsible for checking access tokens

There's still plenty of dependencies on account/device DBs, but this
is a start. This is a breaking change as it adds a required config
value `listen.user_api`.

* Cleanup

* Review comments and test fix
This commit is contained in:
Kegsay 2020-06-16 14:10:55 +01:00 committed by GitHub
parent 57b7fa3db8
commit 9c77022513
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 421 additions and 400 deletions

View file

@ -17,11 +17,9 @@ package routing
import (
"net/http"
"github.com/matrix-org/dendrite/clientapi/auth"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/mediaapi/storage"
@ -44,7 +42,7 @@ func Setup(
publicAPIMux *mux.Router,
cfg *config.Dendrite,
db storage.Database,
deviceDB devices.Database,
userAPI userapi.UserInternalAPI,
client *gomatrixserverlib.Client,
) {
r0mux := publicAPIMux.PathPrefix(pathPrefixR0).Subrouter()
@ -52,16 +50,9 @@ func Setup(
activeThumbnailGeneration := &types.ActiveThumbnailGeneration{
PathToResult: map[string]*types.ThumbnailGenerationResult{},
}
authData := auth.Data{
AccountDB: nil,
DeviceDB: deviceDB,
AppServices: nil,
}
// TODO: Add AS support
r0mux.Handle("/upload", httputil.MakeAuthAPI(
"upload", authData,
func(req *http.Request, _ *authtypes.Device) util.JSONResponse {
"upload", userAPI,
func(req *http.Request, _ *userapi.Device) util.JSONResponse {
return Upload(req, cfg, db, activeThumbnailGeneration)
},
)).Methods(http.MethodPost, http.MethodOptions)