feat: admin APIs for token authenticated registration (#3101)

### Pull Request Checklist

<!-- Please read
https://matrix-org.github.io/dendrite/development/contributing before
submitting your pull request -->

* [x] I have added Go unit tests or [Complement integration
tests](https://github.com/matrix-org/complement) for this PR _or_ I have
justified why this PR doesn't need tests
* [x] Pull request includes a [sign off below using a legally
identifiable
name](https://matrix-org.github.io/dendrite/development/contributing#sign-off)
_or_ I have already signed off privately

Signed-off-by: `Santhoshivan Amudhan santhoshivan23@gmail.com`
This commit is contained in:
santhoshivan23 2023-06-22 22:07:21 +05:30 committed by GitHub
parent a734b112c6
commit 45082d4dce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1474 additions and 1 deletions

View file

@ -33,6 +33,7 @@ import (
"github.com/sirupsen/logrus"
"golang.org/x/crypto/bcrypt"
clientapi "github.com/matrix-org/dendrite/clientapi/api"
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/internal/pushgateway"
@ -63,6 +64,37 @@ type UserInternalAPI struct {
Updater *DeviceListUpdater
}
func (a *UserInternalAPI) PerformAdminCreateRegistrationToken(ctx context.Context, registrationToken *clientapi.RegistrationToken) (bool, error) {
exists, err := a.DB.RegistrationTokenExists(ctx, *registrationToken.Token)
if err != nil {
return false, err
}
if exists {
return false, fmt.Errorf("token: %s already exists", *registrationToken.Token)
}
_, err = a.DB.InsertRegistrationToken(ctx, registrationToken)
if err != nil {
return false, fmt.Errorf("Error creating token: %s"+err.Error(), *registrationToken.Token)
}
return true, nil
}
func (a *UserInternalAPI) PerformAdminListRegistrationTokens(ctx context.Context, returnAll bool, valid bool) ([]clientapi.RegistrationToken, error) {
return a.DB.ListRegistrationTokens(ctx, returnAll, valid)
}
func (a *UserInternalAPI) PerformAdminGetRegistrationToken(ctx context.Context, tokenString string) (*clientapi.RegistrationToken, error) {
return a.DB.GetRegistrationToken(ctx, tokenString)
}
func (a *UserInternalAPI) PerformAdminDeleteRegistrationToken(ctx context.Context, tokenString string) error {
return a.DB.DeleteRegistrationToken(ctx, tokenString)
}
func (a *UserInternalAPI) PerformAdminUpdateRegistrationToken(ctx context.Context, tokenString string, newAttributes map[string]interface{}) (*clientapi.RegistrationToken, error) {
return a.DB.UpdateRegistrationToken(ctx, tokenString, newAttributes)
}
func (a *UserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error {
local, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {