mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 02:43:09 -06:00
Fix interactive registration failing because of being confused with AS registration
This commit is contained in:
parent
1a82e6bc58
commit
1e5ed0c159
|
|
@ -371,16 +371,10 @@ func validateApplicationService(
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
username string,
|
username string,
|
||||||
|
accessToken string,
|
||||||
) (string, *util.JSONResponse) {
|
) (string, *util.JSONResponse) {
|
||||||
// Check if the token if the application service is valid with one we have
|
// Check if the token if the application service is valid with one we have
|
||||||
// registered in the config.
|
// registered in the config.
|
||||||
accessToken, err := auth.ExtractAccessToken(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", &util.JSONResponse{
|
|
||||||
Code: http.StatusUnauthorized,
|
|
||||||
JSON: jsonerror.MissingToken(err.Error()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var matchedApplicationService *config.ApplicationService
|
var matchedApplicationService *config.ApplicationService
|
||||||
for _, appservice := range cfg.Derived.ApplicationServices {
|
for _, appservice := range cfg.Derived.ApplicationServices {
|
||||||
if appservice.ASToken == accessToken {
|
if appservice.ASToken == accessToken {
|
||||||
|
|
@ -543,21 +537,41 @@ func handleRegistrationFlow(
|
||||||
sessions.AddCompletedStage(sessionID, authtypes.LoginTypeSharedSecret)
|
sessions.AddCompletedStage(sessionID, authtypes.LoginTypeSharedSecret)
|
||||||
|
|
||||||
case "", authtypes.LoginTypeApplicationService:
|
case "", authtypes.LoginTypeApplicationService:
|
||||||
// not passing a Auth.Type is allowed for ApplicationServices. So assume that as well
|
// Extract the access token from the request, if there's one to extract
|
||||||
// Check application service register user request is valid.
|
// (which we can know by checking whether the error is nil or not).
|
||||||
// The application service's ID is returned if so.
|
accessToken, err := auth.ExtractAccessToken(req)
|
||||||
appserviceID, err := validateApplicationService(cfg, req, r.Username)
|
|
||||||
if err != nil {
|
|
||||||
return *err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no error, application service was successfully validated.
|
// A missing auth type can mean either the registration is performed by
|
||||||
// Don't need to worry about appending to registration stages as
|
// an AS or the request is made as the first step of a registration
|
||||||
// application service registration is entirely separate.
|
// using the User-Interactive Authentication API. This can be determined
|
||||||
return completeRegistration(
|
// by whether the request contains an access token.
|
||||||
req.Context(), accountDB, deviceDB, r.Username, "", appserviceID,
|
if err == nil || r.Auth.Type != "" {
|
||||||
r.InhibitLogin, r.InitialDisplayName,
|
// If the auth type explicitely relates to Application Services but
|
||||||
)
|
// there's no access token provided, return an error.
|
||||||
|
if err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusUnauthorized,
|
||||||
|
JSON: jsonerror.MissingToken(err.Error()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check application service register user request is valid.
|
||||||
|
// The application service's ID is returned if so.
|
||||||
|
appserviceID, err := validateApplicationService(
|
||||||
|
cfg, req, r.Username, accessToken,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return *err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(), accountDB, deviceDB, r.Username, "", appserviceID,
|
||||||
|
r.InhibitLogin, r.InitialDisplayName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
case authtypes.LoginTypeDummy:
|
case authtypes.LoginTypeDummy:
|
||||||
// there is nothing to do
|
// there is nothing to do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue