mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-03 06:05:12 +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>
96 lines
3.6 KiB
Go
96 lines
3.6 KiB
Go
package view
|
|
|
|
import (
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
global_model "github.com/caos/zitadel/internal/model"
|
|
"github.com/caos/zitadel/internal/view/repository"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
func GetIDPProviderByAggregateIDAndConfigID(db *gorm.DB, table, aggregateID, idpConfigID string) (*model.IDPProviderView, error) {
|
|
policy := new(model.IDPProviderView)
|
|
aggIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyAggregateID, Value: aggregateID, Method: global_model.SearchMethodEquals}
|
|
idpConfigIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyIdpConfigID, Value: idpConfigID, Method: global_model.SearchMethodEquals}
|
|
query := repository.PrepareGetByQuery(table, aggIDQuery, idpConfigIDQuery)
|
|
err := query(db, policy)
|
|
if caos_errs.IsNotFound(err) {
|
|
return nil, caos_errs.ThrowNotFound(nil, "VIEW-Skvi8", "Errors.IAM.LoginPolicy.IdpProviderNotExisting")
|
|
}
|
|
return policy, err
|
|
}
|
|
|
|
func IDPProvidersByIdpConfigID(db *gorm.DB, table string, idpConfigID string) ([]*model.IDPProviderView, error) {
|
|
providers := make([]*model.IDPProviderView, 0)
|
|
queries := []*iam_model.IDPProviderSearchQuery{
|
|
{
|
|
Key: iam_model.IDPProviderSearchKeyIdpConfigID,
|
|
Value: idpConfigID,
|
|
Method: global_model.SearchMethodEquals,
|
|
},
|
|
}
|
|
query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Queries: queries})
|
|
_, err := query(db, &providers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return providers, nil
|
|
}
|
|
|
|
func IDPProvidersByAggregateID(db *gorm.DB, table string, aggregateID string) ([]*model.IDPProviderView, error) {
|
|
providers := make([]*model.IDPProviderView, 0)
|
|
queries := []*iam_model.IDPProviderSearchQuery{
|
|
{
|
|
Key: iam_model.IDPProviderSearchKeyAggregateID,
|
|
Value: aggregateID,
|
|
Method: global_model.SearchMethodEquals,
|
|
},
|
|
}
|
|
query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Queries: queries})
|
|
_, err := query(db, &providers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return providers, nil
|
|
}
|
|
|
|
func SearchIDPProviders(db *gorm.DB, table string, req *iam_model.IDPProviderSearchRequest) ([]*model.IDPProviderView, uint64, error) {
|
|
providers := make([]*model.IDPProviderView, 0)
|
|
query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
|
count, err := query(db, &providers)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return providers, count, nil
|
|
}
|
|
|
|
func PutIDPProvider(db *gorm.DB, table string, provider *model.IDPProviderView) error {
|
|
save := repository.PrepareSave(table)
|
|
return save(db, provider)
|
|
}
|
|
|
|
func PutIDPProviders(db *gorm.DB, table string, providers ...*model.IDPProviderView) error {
|
|
save := repository.PrepareBulkSave(table)
|
|
p := make([]interface{}, len(providers))
|
|
for i, provider := range providers {
|
|
p[i] = provider
|
|
}
|
|
return save(db, p...)
|
|
}
|
|
|
|
func DeleteIDPProvider(db *gorm.DB, table, aggregateID, idpConfigID string) error {
|
|
delete := repository.PrepareDeleteByKeys(table,
|
|
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyAggregateID), Value: aggregateID},
|
|
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyIdpConfigID), Value: idpConfigID},
|
|
)
|
|
return delete(db)
|
|
}
|
|
|
|
func DeleteIDPProvidersByAggregateID(db *gorm.DB, table, aggregateID string) error {
|
|
delete := repository.PrepareDeleteByKeys(table,
|
|
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyAggregateID), Value: aggregateID},
|
|
)
|
|
return delete(db)
|
|
}
|