mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:07:31 +00:00
fix: migrate external id of federated users (#6312)
* feat: migrate external id * implement tests and some renaming * fix projection * cleanup * i18n * fix event type * handle migration for new services as well * typo
This commit is contained in:
@@ -120,6 +120,11 @@ func (h *Handler) handleCallback(w http.ResponseWriter, r *http.Request) {
|
||||
userID, err := h.checkExternalUser(ctx, intent.IDPID, idpUser.GetID())
|
||||
logging.WithFields("intent", intent.AggregateID).OnError(err).Error("could not check if idp user already exists")
|
||||
|
||||
if userID == "" {
|
||||
userID, err = h.tryMigrateExternalUser(ctx, intent.IDPID, idpUser, idpSession)
|
||||
logging.WithFields("intent", intent.AggregateID).OnError(err).Error("migration check failed")
|
||||
}
|
||||
|
||||
token, err := h.commands.SucceedIDPIntent(ctx, intent, idpUser, idpSession, userID)
|
||||
if err != nil {
|
||||
redirectToFailureURLErr(w, r, intent, z_errs.ThrowInternal(err, "IDP-JdD3g", "Errors.Intent.TokenCreationFailed"))
|
||||
@@ -128,6 +133,22 @@ func (h *Handler) handleCallback(w http.ResponseWriter, r *http.Request) {
|
||||
redirectToSuccessURL(w, r, intent, token, userID)
|
||||
}
|
||||
|
||||
func (h *Handler) tryMigrateExternalUser(ctx context.Context, idpID string, idpUser idp.User, idpSession idp.Session) (userID string, err error) {
|
||||
migration, ok := idpSession.(idp.SessionSupportsMigration)
|
||||
if !ok {
|
||||
return "", nil
|
||||
}
|
||||
previousID, err := migration.RetrievePreviousID()
|
||||
if err != nil || previousID == "" {
|
||||
return "", err
|
||||
}
|
||||
userID, err = h.checkExternalUser(ctx, idpID, previousID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return userID, h.commands.MigrateUserIDP(ctx, userID, "", idpID, previousID, idpUser.GetID())
|
||||
}
|
||||
|
||||
func (h *Handler) parseCallbackRequest(r *http.Request) (*externalIDPCallbackData, error) {
|
||||
data := new(externalIDPCallbackData)
|
||||
err := h.parser.Parse(r, data)
|
||||
@@ -196,7 +217,7 @@ func (h *Handler) fetchIDPUser(ctx context.Context, identityProvider idp.Provide
|
||||
case *openid.Provider:
|
||||
session = &openid.Session{Provider: provider, Code: code}
|
||||
case *azuread.Provider:
|
||||
session = &oauth.Session{Provider: provider.Provider, Code: code}
|
||||
session = &azuread.Session{Session: &oauth.Session{Provider: provider.Provider, Code: code}}
|
||||
case *github.Provider:
|
||||
session = &oauth.Session{Provider: provider.Provider, Code: code}
|
||||
case *gitlab.Provider:
|
||||
|
Reference in New Issue
Block a user