mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-01 15:57:24 +00:00

* 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>
153 lines
3.8 KiB
Go
153 lines
3.8 KiB
Go
package model
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"github.com/caos/logging"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/model"
|
|
)
|
|
|
|
type IDPConfig struct {
|
|
es_models.ObjectRoot
|
|
IDPConfigID string `json:"idpConfigId"`
|
|
State int32 `json:"-"`
|
|
Name string `json:"name,omitempty"`
|
|
Type int32 `json:"idpType,omitempty"`
|
|
LogoSrc []byte `json:"logoSrc,omitempty"`
|
|
|
|
OIDCIDPConfig *OIDCIDPConfig `json:"-"`
|
|
}
|
|
|
|
type IDPConfigID struct {
|
|
es_models.ObjectRoot
|
|
IDPConfigID string `json:"idpConfigId"`
|
|
}
|
|
|
|
func GetIDPConfig(idps []*IDPConfig, id string) (int, *IDPConfig) {
|
|
for i, idp := range idps {
|
|
if idp.IDPConfigID == id {
|
|
return i, idp
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|
|
|
|
func (c *IDPConfig) Changes(changed *IDPConfig) map[string]interface{} {
|
|
changes := make(map[string]interface{}, 1)
|
|
changes["idpConfigId"] = c.IDPConfigID
|
|
if changed.Name != "" && c.Name != changed.Name {
|
|
changes["name"] = changed.Name
|
|
}
|
|
if changed.LogoSrc != nil && bytes.Equal(c.LogoSrc, changed.LogoSrc) {
|
|
changes["logoSrc"] = changed.LogoSrc
|
|
}
|
|
return changes
|
|
}
|
|
|
|
func IDPConfigsToModel(idps []*IDPConfig) []*model.IDPConfig {
|
|
convertedIDPConfigs := make([]*model.IDPConfig, len(idps))
|
|
for i, idp := range idps {
|
|
convertedIDPConfigs[i] = IDPConfigToModel(idp)
|
|
}
|
|
return convertedIDPConfigs
|
|
}
|
|
|
|
func IDPConfigsFromModel(idps []*model.IDPConfig) []*IDPConfig {
|
|
convertedIDPConfigs := make([]*IDPConfig, len(idps))
|
|
for i, idp := range idps {
|
|
convertedIDPConfigs[i] = IDPConfigFromModel(idp)
|
|
}
|
|
return convertedIDPConfigs
|
|
}
|
|
|
|
func IDPConfigFromModel(idp *model.IDPConfig) *IDPConfig {
|
|
converted := &IDPConfig{
|
|
ObjectRoot: idp.ObjectRoot,
|
|
IDPConfigID: idp.IDPConfigID,
|
|
Name: idp.Name,
|
|
State: int32(idp.State),
|
|
Type: int32(idp.Type),
|
|
LogoSrc: idp.LogoSrc,
|
|
}
|
|
if idp.OIDCConfig != nil {
|
|
converted.OIDCIDPConfig = OIDCIDPConfigFromModel(idp.OIDCConfig)
|
|
}
|
|
return converted
|
|
}
|
|
|
|
func IDPConfigToModel(idp *IDPConfig) *model.IDPConfig {
|
|
converted := &model.IDPConfig{
|
|
ObjectRoot: idp.ObjectRoot,
|
|
IDPConfigID: idp.IDPConfigID,
|
|
Name: idp.Name,
|
|
LogoSrc: idp.LogoSrc,
|
|
State: model.IDPConfigState(idp.State),
|
|
Type: model.IdpConfigType(idp.Type),
|
|
}
|
|
if idp.OIDCIDPConfig != nil {
|
|
converted.OIDCConfig = OIDCIDPConfigToModel(idp.OIDCIDPConfig)
|
|
}
|
|
return converted
|
|
}
|
|
|
|
func (iam *IAM) appendAddIDPConfigEvent(event *es_models.Event) error {
|
|
idp := new(IDPConfig)
|
|
err := idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
idp.ObjectRoot.CreationDate = event.CreationDate
|
|
iam.IDPs = append(iam.IDPs, idp)
|
|
return nil
|
|
}
|
|
|
|
func (iam *IAM) appendChangeIDPConfigEvent(event *es_models.Event) error {
|
|
idp := new(IDPConfig)
|
|
err := idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if i, idpConfig := GetIDPConfig(iam.IDPs, idp.IDPConfigID); idpConfig != nil {
|
|
iam.IDPs[i].SetData(event)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (iam *IAM) appendRemoveIDPConfigEvent(event *es_models.Event) error {
|
|
idp := new(IDPConfig)
|
|
err := idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if i, idpConfig := GetIDPConfig(iam.IDPs, idp.IDPConfigID); idpConfig != nil {
|
|
iam.IDPs[i] = iam.IDPs[len(iam.IDPs)-1]
|
|
iam.IDPs[len(iam.IDPs)-1] = nil
|
|
iam.IDPs = iam.IDPs[:len(iam.IDPs)-1]
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (iam *IAM) appendIDPConfigStateEvent(event *es_models.Event, state model.IDPConfigState) error {
|
|
idp := new(IDPConfig)
|
|
err := idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if i, idpConfig := GetIDPConfig(iam.IDPs, idp.IDPConfigID); idpConfig != nil {
|
|
idpConfig.State = int32(state)
|
|
iam.IDPs[i] = idpConfig
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *IDPConfig) SetData(event *es_models.Event) error {
|
|
c.ObjectRoot.AppendEvent(event)
|
|
if err := json.Unmarshal(event.Data, c); err != nil {
|
|
logging.Log("EVEN-Msj9w").WithError(err).Error("could not unmarshal event data")
|
|
return err
|
|
}
|
|
return nil
|
|
}
|