zitadel/internal/v2/business/iam/idp_oidc_config.go

45 lines
1.2 KiB
Go
Raw Normal View History

2020-11-25 20:04:32 +01:00
package iam
import (
"context"
2020-11-26 13:14:07 +01:00
"github.com/caos/zitadel/internal/crypto"
2020-11-25 20:04:32 +01:00
iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/v2/repository/iam"
2020-11-26 13:14:07 +01:00
"github.com/caos/zitadel/internal/v2/repository/idp/oidc"
2020-11-25 20:04:32 +01:00
)
2020-11-27 11:30:56 +01: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 20:04:32 +01:00
if err != nil {
return nil, err
}
2020-11-27 11:30:56 +01:00
var clientSecret *crypto.CryptoValue
if config.ClientSecretString != "" {
clientSecret, err = crypto.Crypt([]byte(config.ClientSecretString), r.secretCrypto)
2020-11-26 13:14:07 +01:00
if err != nil {
return nil, err
}
2020-11-27 11:30:56 +01:00
}
2020-11-27 13:29:35 +01:00
aggregate := iam.AggregateFromWriteModel(&writeModel.WriteModel).
2020-11-27 11:30:56 +01:00
PushIDPOIDCConfigChanged(
2020-11-26 13:14:07 +01:00
ctx,
2020-11-27 11:30:56 +01:00
writeModel,
config.ClientID,
config.Issuer,
2020-11-26 13:14:07 +01:00
clientSecret,
2020-11-27 11:30:56 +01:00
oidc.MappingField(config.IDPDisplayNameMapping),
oidc.MappingField(config.UsernameMapping),
config.Scopes...)
2020-11-26 13:14:07 +01:00
2020-11-30 08:35:40 +01:00
err = r.eventstore.PushAggregate(ctx, writeModel, aggregate)
2020-11-26 13:14:07 +01:00
if err != nil {
return nil, err
}
2020-11-27 11:30:56 +01:00
return writeModelToIDPOIDCConfig(&writeModel.ConfigWriteModel), nil
2020-11-26 09:19:14 +01:00
}