diff --git a/src/github.com/matrix-org/dendrite/appservice/appservice.go b/src/github.com/matrix-org/dendrite/appservice/appservice.go index fed32369..25c71325 100644 --- a/src/github.com/matrix-org/dendrite/appservice/appservice.go +++ b/src/github.com/matrix-org/dendrite/appservice/appservice.go @@ -141,3 +141,27 @@ func generateAppServiceAccount( return nil } + +// generateAppServiceAccounts creates a dummy account based off the +// `sender_localpart` field of each application service if it doesn't +// exist already +func generateAppServiceAccount( + accountsDB *accounts.Database, + deviceDB *devices.Database, + as config.ApplicationService, +) error { + ctx := context.Background() + + // Create an account for the application service + acc, err := accountsDB.CreateAccount(ctx, as.SenderLocalpart, "", as.ID) + if err != nil { + return err + } else if acc == nil { + // This account already exists + return nil + } + + // Create a dummy device with a dummy token for the application service + _, err = deviceDB.CreateDevice(ctx, as.SenderLocalpart, nil, as.ASToken, &as.SenderLocalpart) + return err +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go b/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go index 98c2b625..c2e61441 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go @@ -83,9 +83,12 @@ func VerifyUserFromRequest( } } - userID := req.URL.Query().Get("user_id") - if appService != nil && userID != "" { + if appService != nil { + userID := req.URL.Query().Get("user_id") localpart, err := userutil.ParseUsernameParam(userID, nil) + if userID == "" { + localpart = appService.SenderLocalpart + } if err != nil { return nil, &util.JSONResponse{ Code: http.StatusBadRequest, diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-appservice-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-appservice-server/main.go new file mode 100644 index 00000000..dcaea513 --- /dev/null +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-appservice-server/main.go @@ -0,0 +1,39 @@ +// Copyright 2018 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "github.com/matrix-org/dendrite/appservice" + "github.com/matrix-org/dendrite/common/basecomponent" + "github.com/matrix-org/dendrite/common/transactions" +) + +func main() { + cfg := basecomponent.ParseFlags() + base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI") + + defer base.Close() // nolint: errcheck + accountDB := base.CreateAccountsDB() + deviceDB := base.CreateDeviceDB() + federation := base.CreateFederationClient() + alias, _, query := base.CreateHTTPRoomserverAPIs() + cache := transactions.New() + + appservice.SetupAppServiceAPIComponent( + base, accountDB, deviceDB, federation, alias, query, cache, + ) + + base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationSender)) +} diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go index 84c2b394..e4998dcc 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go @@ -65,6 +65,10 @@ func main() { mediaapi.SetupMediaAPIComponent(base, deviceDB) publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query) +<<<<<<< HEAD +======= + appservice.SetupAppServiceAPIComponent(base, accountDB, deviceDB, federation, alias, query, transactions.New()) +>>>>>>> c65838c9... Generate sender_localpart user for each AS on startup httpHandler := common.WrapHandlerInCORS(base.APIMux)