Skip to content

Commit

Permalink
🏗️ Allow saving password and threepid info on application service reg…
Browse files Browse the repository at this point in the history
…istration.
  • Loading branch information
Danieloni1 committed Jan 25, 2024
1 parent 7e16873 commit 733ad9a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
41 changes: 23 additions & 18 deletions clientapi/routing/key_crosssigning.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/userapi/api"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
)
Expand All @@ -50,26 +51,30 @@ func UploadCrossSigningDeviceKeys(
if sessionID == "" {
sessionID = util.RandomString(sessionIDLength)
}
if uploadReq.Auth.Type != authtypes.LoginTypePassword {
return util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: newUserInteractiveResponse(
sessionID,
[]authtypes.Flow{
{
Stages: []authtypes.LoginType{authtypes.LoginTypePassword},

//! GlobeKeeper Customization: If user was registered with appservice (like BridgeAS), then we allow it to upload keys without a password
if device.AccountType != userapi.AccountTypeAppService {
if uploadReq.Auth.Type != authtypes.LoginTypePassword {
return util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: newUserInteractiveResponse(
sessionID,
[]authtypes.Flow{
{
Stages: []authtypes.LoginType{authtypes.LoginTypePassword},
},
},
},
nil,
),
nil,
),
}
}
typePassword := auth.LoginTypePassword{
UserApi: accountAPI,
Config: cfg,
}
if _, authErr := typePassword.Login(req.Context(), &uploadReq.Auth.PasswordRequest); authErr != nil {
return *authErr
}
}
typePassword := auth.LoginTypePassword{
UserApi: accountAPI,
Config: cfg,
}
if _, authErr := typePassword.Login(req.Context(), &uploadReq.Auth.PasswordRequest); authErr != nil {
return *authErr
}
sessions.addCompletedSessionStage(sessionID, authtypes.LoginTypePassword)

Expand Down
18 changes: 18 additions & 0 deletions clientapi/routing/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ type registerRequest struct {
// Application Services place Type in the root of their registration
// request, whereas clients place it in the authDict struct.
Type authtypes.LoginType `json:"type"`

// GlobeKeeper custom
Email string `json:"email"`
}

type authDict struct {
Expand Down Expand Up @@ -818,6 +821,21 @@ func handleApplicationServiceRegistration(
return *err
}

//! Custom GlobeKeeper logic to support AS registration with email (3pid) & password.
if r.Email != "" && r.Password != "" {
// If no error, application service was successfully validated.
// Don't need to worry about appending to registration stages as
// application service registration is entirely separate.
return completeRegistration(
req.Context(), userAPI, r.Username, r.ServerName, "", r.Password, appserviceID, req.RemoteAddr, req.UserAgent(), r.Auth.Session,
r.InhibitLogin, r.InitialDisplayName, r.DeviceID, userapi.AccountTypeAppService, &authtypes.ThreePID{
Address: r.Email,
Medium: "email",
AddedAt: time.Now().Unix(),
ValidatedAt: time.Now().Unix(),
},
)
}
// If no error, application service was successfully validated.
// Don't need to worry about appending to registration stages as
// application service registration is entirely separate.
Expand Down

0 comments on commit 733ad9a

Please sign in to comment.