mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 11:58:02 +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>
109 lines
3.5 KiB
Go
109 lines
3.5 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/caos/logging"
|
|
"github.com/caos/zitadel/internal/crypto"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/model"
|
|
"github.com/lib/pq"
|
|
"reflect"
|
|
)
|
|
|
|
type OIDCIDPConfig struct {
|
|
es_models.ObjectRoot
|
|
IDPConfigID string `json:"idpConfigId"`
|
|
ClientID string `json:"clientId"`
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
Issuer string `json:"issuer,omitempty"`
|
|
Scopes pq.StringArray `json:"scopes,omitempty"`
|
|
IDPDisplayNameMapping int32 `json:"idpDisplayNameMapping,omitempty"`
|
|
UsernameMapping int32 `json:"usernameMapping,omitempty"`
|
|
}
|
|
|
|
func (c *OIDCIDPConfig) Changes(changed *OIDCIDPConfig) map[string]interface{} {
|
|
changes := make(map[string]interface{}, 1)
|
|
changes["idpConfigId"] = c.IDPConfigID
|
|
if c.ClientID != changed.ClientID {
|
|
changes["clientId"] = changed.ClientID
|
|
}
|
|
if c.ClientSecret != nil && c.ClientSecret != changed.ClientSecret {
|
|
changes["clientSecret"] = changed.ClientSecret
|
|
}
|
|
if c.Issuer != changed.Issuer {
|
|
changes["issuer"] = changed.Issuer
|
|
}
|
|
if !reflect.DeepEqual(c.Scopes, changed.Scopes) {
|
|
changes["scopes"] = changed.Scopes
|
|
}
|
|
if c.IDPDisplayNameMapping != changed.IDPDisplayNameMapping {
|
|
changes["idpDisplayNameMapping"] = changed.IDPDisplayNameMapping
|
|
}
|
|
if c.UsernameMapping != changed.UsernameMapping {
|
|
changes["usernameMapping"] = changed.UsernameMapping
|
|
}
|
|
return changes
|
|
}
|
|
|
|
func OIDCIDPConfigFromModel(config *model.OIDCIDPConfig) *OIDCIDPConfig {
|
|
return &OIDCIDPConfig{
|
|
ObjectRoot: config.ObjectRoot,
|
|
IDPConfigID: config.IDPConfigID,
|
|
ClientID: config.ClientID,
|
|
ClientSecret: config.ClientSecret,
|
|
Issuer: config.Issuer,
|
|
Scopes: config.Scopes,
|
|
IDPDisplayNameMapping: int32(config.IDPDisplayNameMapping),
|
|
UsernameMapping: int32(config.UsernameMapping),
|
|
}
|
|
}
|
|
|
|
func OIDCIDPConfigToModel(config *OIDCIDPConfig) *model.OIDCIDPConfig {
|
|
return &model.OIDCIDPConfig{
|
|
ObjectRoot: config.ObjectRoot,
|
|
IDPConfigID: config.IDPConfigID,
|
|
ClientID: config.ClientID,
|
|
ClientSecret: config.ClientSecret,
|
|
Issuer: config.Issuer,
|
|
Scopes: config.Scopes,
|
|
IDPDisplayNameMapping: model.OIDCMappingField(config.IDPDisplayNameMapping),
|
|
UsernameMapping: model.OIDCMappingField(config.UsernameMapping),
|
|
}
|
|
}
|
|
|
|
func (iam *IAM) appendAddOIDCIDPConfigEvent(event *es_models.Event) error {
|
|
config := new(OIDCIDPConfig)
|
|
err := config.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
config.ObjectRoot.CreationDate = event.CreationDate
|
|
if i, idpConfig := GetIDPConfig(iam.IDPs, config.IDPConfigID); idpConfig != nil {
|
|
iam.IDPs[i].Type = int32(model.IDPConfigTypeOIDC)
|
|
iam.IDPs[i].OIDCIDPConfig = config
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (iam *IAM) appendChangeOIDCIDPConfigEvent(event *es_models.Event) error {
|
|
config := new(OIDCIDPConfig)
|
|
err := config.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if i, idpConfig := GetIDPConfig(iam.IDPs, config.IDPConfigID); idpConfig != nil {
|
|
iam.IDPs[i].OIDCIDPConfig.SetData(event)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (o *OIDCIDPConfig) SetData(event *es_models.Event) error {
|
|
o.ObjectRoot.AppendEvent(event)
|
|
if err := json.Unmarshal(event.Data, o); err != nil {
|
|
logging.Log("EVEN-Msh8s").WithError(err).Error("could not unmarshal event data")
|
|
return err
|
|
}
|
|
return nil
|
|
}
|