zitadel/internal/user/repository/view/model/external_idps.go
Fabi 320ddfa46d
feat: Identity brokering (#730)
* 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>
2020-09-18 13:26:28 +02:00

92 lines
3.1 KiB
Go

package model
import (
"encoding/json"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/models"
"github.com/caos/zitadel/internal/user/model"
es_model "github.com/caos/zitadel/internal/user/repository/eventsourcing/model"
"time"
)
const (
ExternalIDPKeyExternalUserID = "external_user_id"
ExternalIDPKeyUserID = "user_id"
ExternalIDPKeyIDPConfigID = "idp_config_id"
ExternalIDPKeyResourceOwner = "resource_owner"
)
type ExternalIDPView struct {
ExternalUserID string `json:"userID" gorm:"column:external_user_id;primary_key"`
IDPConfigID string `json:"idpConfigID" gorm:"column:idp_config_id;primary_key"`
UserID string `json:"-" gorm:"column:user_id"`
IDPName string `json:"-" gorm:"column:idp_name"`
UserDisplayName string `json:"displayName" gorm:"column:user_display_name"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
}
func ExternalIDPViewFromModel(externalIDP *model.ExternalIDPView) *ExternalIDPView {
return &ExternalIDPView{
UserID: externalIDP.UserID,
IDPConfigID: externalIDP.IDPConfigID,
ExternalUserID: externalIDP.ExternalUserID,
IDPName: externalIDP.IDPName,
UserDisplayName: externalIDP.UserDisplayName,
Sequence: externalIDP.Sequence,
CreationDate: externalIDP.CreationDate,
ChangeDate: externalIDP.ChangeDate,
ResourceOwner: externalIDP.ResourceOwner,
}
}
func ExternalIDPViewToModel(externalIDP *ExternalIDPView) *model.ExternalIDPView {
return &model.ExternalIDPView{
UserID: externalIDP.UserID,
IDPConfigID: externalIDP.IDPConfigID,
ExternalUserID: externalIDP.ExternalUserID,
IDPName: externalIDP.IDPName,
UserDisplayName: externalIDP.UserDisplayName,
Sequence: externalIDP.Sequence,
CreationDate: externalIDP.CreationDate,
ChangeDate: externalIDP.ChangeDate,
ResourceOwner: externalIDP.ResourceOwner,
}
}
func ExternalIDPViewsToModel(externalIDPs []*ExternalIDPView) []*model.ExternalIDPView {
result := make([]*model.ExternalIDPView, len(externalIDPs))
for i, r := range externalIDPs {
result[i] = ExternalIDPViewToModel(r)
}
return result
}
func (i *ExternalIDPView) AppendEvent(event *models.Event) (err error) {
i.Sequence = event.Sequence
i.ChangeDate = event.CreationDate
switch event.Type {
case es_model.HumanExternalIDPAdded:
i.setRootData(event)
i.CreationDate = event.CreationDate
err = i.SetData(event)
}
return err
}
func (r *ExternalIDPView) setRootData(event *models.Event) {
r.UserID = event.AggregateID
r.ResourceOwner = event.ResourceOwner
}
func (r *ExternalIDPView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-48sfs").WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
}
return nil
}