mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
320ddfa46d
* feat: add/ remove external idps * feat: external idp add /remove * fix: auth proto * fix: handle login * feat: loginpolicy on authrequest * feat: idp providers on login * feat: link external idp * fix: check login policy on check username * feat: add mapping fields for idp config * feat: use user org id if existing * feat: use user org id if existing * feat: register external user * feat: register external user * feat: user linking * feat: user linking * feat: design external login * feat: design external login * fix: tests * fix: regenerate login design * feat: next step test linking process * feat: next step test linking process * feat: cascade remove external idps on user * fix: tests * fix: tests * feat: external idp requsts on users * fix: generate protos * feat: login styles * feat: login styles * fix: link user * fix: register user on specifig org * fix: user linking * fix: register external, linking auto * fix: remove unnecessary request from proto * fix: tests * fix: new oidc package * fix: migration version * fix: policy permissions * Update internal/ui/login/static/i18n/en.yaml Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/ui/login/static/i18n/en.yaml Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/ui/login/handler/renderer.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/ui/login/handler/renderer.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: pr requests * Update internal/ui/login/handler/link_users_handler.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: pr requests * fix: pr requests * fix: pr requests * fix: login name size * fix: profile image light * fix: colors * fix: pr requests * fix: remove redirect uri validator * fix: remove redirect uri validator Co-authored-by: Livio Amstutz <livio.a@gmail.com>
83 lines
2.6 KiB
Go
83 lines
2.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/caos/logging"
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/eventstore/spooler"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
)
|
|
|
|
type IDPConfig struct {
|
|
handler
|
|
}
|
|
|
|
const (
|
|
idpConfigTable = "auth.idp_configs"
|
|
)
|
|
|
|
func (m *IDPConfig) ViewModel() string {
|
|
return idpConfigTable
|
|
}
|
|
|
|
func (m *IDPConfig) EventQuery() (*models.SearchQuery, error) {
|
|
sequence, err := m.view.GetLatestIDPConfigSequence()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.OrgAggregate, iam_es_model.IAMAggregate).
|
|
LatestSequenceFilter(sequence.CurrentSequence), nil
|
|
}
|
|
|
|
func (m *IDPConfig) Reduce(event *models.Event) (err error) {
|
|
switch event.AggregateType {
|
|
case model.OrgAggregate:
|
|
err = m.processIdpConfig(iam_model.IDPProviderTypeOrg, event)
|
|
case iam_es_model.IAMAggregate:
|
|
err = m.processIdpConfig(iam_model.IDPProviderTypeSystem, event)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (m *IDPConfig) processIdpConfig(providerType iam_model.IDPProviderType, event *models.Event) (err error) {
|
|
idp := new(iam_view_model.IDPConfigView)
|
|
switch event.Type {
|
|
case model.IDPConfigAdded,
|
|
iam_es_model.IDPConfigAdded:
|
|
err = idp.AppendEvent(providerType, event)
|
|
case model.IDPConfigChanged, iam_es_model.IDPConfigChanged,
|
|
model.OIDCIDPConfigAdded, iam_es_model.OIDCIDPConfigAdded,
|
|
model.OIDCIDPConfigChanged, iam_es_model.OIDCIDPConfigChanged:
|
|
err = idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
idp, err = m.view.IDPConfigByID(idp.IDPConfigID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = idp.AppendEvent(providerType, event)
|
|
case model.IDPConfigRemoved, iam_es_model.IDPConfigRemoved:
|
|
err = idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return m.view.DeleteIDPConfig(idp.IDPConfigID, event.Sequence)
|
|
default:
|
|
return m.view.ProcessedIDPConfigSequence(event.Sequence)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return m.view.PutIDPConfig(idp, idp.Sequence)
|
|
}
|
|
|
|
func (m *IDPConfig) OnError(event *models.Event, err error) error {
|
|
logging.LogWithFields("SPOOL-Ejf8s", "id", event.AggregateID).WithError(err).Warn("something went wrong in idp config handler")
|
|
return spooler.HandleError(event, err, m.view.GetLatestIDPConfigFailedEvent, m.view.ProcessedIDPConfigFailedEvent, m.view.ProcessedIDPConfigSequence, m.errorCountUntilSkip)
|
|
}
|