2020-11-25 19:04:32 +00:00
|
|
|
package iam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-11-26 12:14:07 +00:00
|
|
|
"github.com/caos/zitadel/internal/crypto"
|
2020-11-25 19:04:32 +00:00
|
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
|
|
"github.com/caos/zitadel/internal/v2/repository/iam"
|
2020-11-26 12:14:07 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/repository/idp/oidc"
|
2020-11-25 19:04:32 +00:00
|
|
|
)
|
|
|
|
|
2020-11-27 10:30:56 +00:00
|
|
|
func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.OIDCIDPConfig) (*iam_model.OIDCIDPConfig, error) {
|
|
|
|
writeModel := iam.NewIDPOIDCConfigWriteModel(config.AggregateID, config.IDPConfigID)
|
|
|
|
err := r.eventstore.FilterToQueryReducer(ctx, writeModel)
|
2020-11-25 19:04:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-11-27 10:30:56 +00:00
|
|
|
var clientSecret *crypto.CryptoValue
|
|
|
|
if config.ClientSecretString != "" {
|
|
|
|
clientSecret, err = crypto.Crypt([]byte(config.ClientSecretString), r.secretCrypto)
|
2020-11-26 12:14:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-27 10:30:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 12:29:35 +00:00
|
|
|
aggregate := iam.AggregateFromWriteModel(&writeModel.WriteModel).
|
2020-11-27 10:30:56 +00:00
|
|
|
PushIDPOIDCConfigChanged(
|
2020-11-26 12:14:07 +00:00
|
|
|
ctx,
|
2020-11-27 10:30:56 +00:00
|
|
|
writeModel,
|
|
|
|
config.ClientID,
|
|
|
|
config.Issuer,
|
2020-11-26 12:14:07 +00:00
|
|
|
clientSecret,
|
2020-11-27 10:30:56 +00:00
|
|
|
oidc.MappingField(config.IDPDisplayNameMapping),
|
|
|
|
oidc.MappingField(config.UsernameMapping),
|
|
|
|
config.Scopes...)
|
2020-11-26 12:14:07 +00:00
|
|
|
|
2020-11-30 07:35:40 +00:00
|
|
|
err = r.eventstore.PushAggregate(ctx, writeModel, aggregate)
|
2020-11-26 12:14:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-11-27 10:30:56 +00:00
|
|
|
return writeModelToIDPOIDCConfig(&writeModel.ConfigWriteModel), nil
|
2020-11-26 08:19:14 +00:00
|
|
|
}
|