Fall back to numeric localpart if there is no suggested username.

Fixes https://github.com/matrix-org/dendrite/issues/2498.
This commit is contained in:
Tommie Gannert 2022-05-27 22:29:20 +02:00
parent 09f0dca6aa
commit f814f9bdf1

View file

@ -21,6 +21,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"
@ -219,7 +220,12 @@ func SSOCallback(
localpart = result.SuggestedUserID
if localpart == "" {
util.GetLogger(ctx).WithError(err).WithField("ssoIdentifier", result.Identifier).Info("no suggested user ID from SSO provider")
localpart = result.Identifier.Subject
var res uapi.QueryNumericLocalpartResponse
if err := userAPI.QueryNumericLocalpart(ctx, &res); err != nil {
util.GetLogger(ctx).WithError(err).WithField("ssoIdentifier", result.Identifier).Error("failed to generate numeric localpart")
return jsonerror.InternalServerError()
}
localpart = strconv.FormatInt(res.ID, 10)
}
ok, resp := registerSSOAccount(ctx, userAPI, result.Identifier, localpart)
@ -254,6 +260,7 @@ type userAPIForSSO interface {
PerformAccountCreation(ctx context.Context, req *uapi.PerformAccountCreationRequest, res *uapi.PerformAccountCreationResponse) error
PerformSaveSSOAssociation(ctx context.Context, req *uapi.PerformSaveSSOAssociationRequest, res *struct{}) error
QueryLocalpartForSSO(ctx context.Context, req *uapi.QueryLocalpartForSSORequest, res *uapi.QueryLocalpartForSSOResponse) error
QueryNumericLocalpart(ctx context.Context, res *uapi.QueryNumericLocalpartResponse) error
}
// formatNonce creates a random nonce that also contains the URL.