mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-01 13:53:08 +00:00
resuse newCryptoCode
This commit is contained in:
@@ -16,7 +16,7 @@ type cryptoCode struct {
|
|||||||
expiry time.Duration
|
expiry time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCryptoCodeWithExpiry(ctx context.Context, filter preparation.FilterToQueryReducer, typ domain.SecretGeneratorType, alg crypto.Crypto) (*cryptoCode, error) {
|
func newCryptoCode(ctx context.Context, filter preparation.FilterToQueryReducer, typ domain.SecretGeneratorType, alg crypto.Crypto) (*cryptoCode, error) {
|
||||||
config, err := secretGeneratorConfig(ctx, filter, typ)
|
config, err := secretGeneratorConfig(ctx, filter, typ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -39,22 +39,6 @@ func newCryptoCodeWithExpiry(ctx context.Context, filter preparation.FilterToQue
|
|||||||
return code, nil
|
return code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCryptoCodeWithPlain(ctx context.Context, filter preparation.FilterToQueryReducer, typ domain.SecretGeneratorType, alg crypto.Crypto) (value *crypto.CryptoValue, plain string, err error) {
|
|
||||||
config, err := secretGeneratorConfig(ctx, filter, typ)
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch a := alg.(type) {
|
|
||||||
case crypto.HashAlgorithm:
|
|
||||||
return crypto.NewCode(crypto.NewHashGenerator(*config, a))
|
|
||||||
case crypto.EncryptionAlgorithm:
|
|
||||||
return crypto.NewCode(crypto.NewEncryptionGenerator(*config, a))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, "", errors.ThrowInvalidArgument(nil, "V2-NGESt", "Errors.Internal")
|
|
||||||
}
|
|
||||||
|
|
||||||
func secretGeneratorConfig(ctx context.Context, filter preparation.FilterToQueryReducer, typ domain.SecretGeneratorType) (*crypto.GeneratorConfig, error) {
|
func secretGeneratorConfig(ctx context.Context, filter preparation.FilterToQueryReducer, typ domain.SecretGeneratorType) (*crypto.GeneratorConfig, error) {
|
||||||
wm := NewInstanceSecretGeneratorConfigWriteModel(ctx, typ)
|
wm := NewInstanceSecretGeneratorConfigWriteModel(ctx, typ)
|
||||||
events, err := filter(ctx, wm.Query())
|
events, err := filter(ctx, wm.Query())
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ func (e *Email) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newEmailCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (*cryptoCode, error) {
|
func newEmailCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (*cryptoCode, error) {
|
||||||
return newCryptoCodeWithExpiry(ctx, filter, domain.SecretGeneratorTypeVerifyEmailCode, alg)
|
return newCryptoCode(ctx, filter, domain.SecretGeneratorTypeVerifyEmailCode, alg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ type Phone struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newPhoneCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (*cryptoCode, error) {
|
func newPhoneCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (*cryptoCode, error) {
|
||||||
return newCryptoCodeWithExpiry(ctx, filter, domain.SecretGeneratorTypeVerifyPhoneCode, alg)
|
return newCryptoCode(ctx, filter, domain.SecretGeneratorTypeVerifyPhoneCode, alg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ type AddApp struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAppClientSecret(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.HashAlgorithm) (value *crypto.CryptoValue, plain string, err error) {
|
func newAppClientSecret(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.HashAlgorithm) (*cryptoCode, error) {
|
||||||
return newCryptoCodeWithPlain(ctx, filter, domain.SecretGeneratorTypeAppSecret, alg)
|
return newCryptoCode(ctx, filter, domain.SecretGeneratorTypeAppSecret, alg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commands) ChangeApplication(ctx context.Context, projectID string, appChange domain.Application, resourceOwner string) (*domain.ObjectDetails, error) {
|
func (c *Commands) ChangeApplication(ctx context.Context, projectID string, appChange domain.Application, resourceOwner string) (*domain.ObjectDetails, error) {
|
||||||
|
|||||||
@@ -44,10 +44,11 @@ func (c *Commands) AddAPIAppCommand(app *addAPIApp, clientSecretAlg crypto.HashA
|
|||||||
}
|
}
|
||||||
|
|
||||||
if app.AuthMethodType == domain.APIAuthMethodTypeBasic {
|
if app.AuthMethodType == domain.APIAuthMethodTypeBasic {
|
||||||
app.ClientSecret, app.ClientSecretPlain, err = newAppClientSecret(ctx, filter, clientSecretAlg)
|
code, err := newAppClientSecret(ctx, filter, clientSecretAlg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
app.ClientSecret, app.ClientSecretPlain = code.value, code.plain
|
||||||
}
|
}
|
||||||
|
|
||||||
return []eventstore.Command{
|
return []eventstore.Command{
|
||||||
|
|||||||
@@ -77,10 +77,11 @@ func (c *Commands) AddOIDCAppCommand(app *addOIDCApp, clientSecretAlg crypto.Has
|
|||||||
}
|
}
|
||||||
|
|
||||||
if app.AuthMethodType == domain.OIDCAuthMethodTypeBasic || app.AuthMethodType == domain.OIDCAuthMethodTypePost {
|
if app.AuthMethodType == domain.OIDCAuthMethodTypeBasic || app.AuthMethodType == domain.OIDCAuthMethodTypePost {
|
||||||
app.ClientSecret, app.ClientSecretPlain, err = newAppClientSecret(ctx, filter, clientSecretAlg)
|
code, err := newAppClientSecret(ctx, filter, clientSecretAlg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
app.ClientSecret, app.ClientSecretPlain = code.value, code.plain
|
||||||
}
|
}
|
||||||
|
|
||||||
return []eventstore.Command{
|
return []eventstore.Command{
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ func ExistsUser(ctx context.Context, filter preparation.FilterToQueryReducer, id
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newUserInitCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (*cryptoCode, error) {
|
func newUserInitCode(ctx context.Context, filter preparation.FilterToQueryReducer, alg crypto.EncryptionAlgorithm) (*cryptoCode, error) {
|
||||||
return newCryptoCodeWithExpiry(ctx, filter, domain.SecretGeneratorTypeInitCode, alg)
|
return newCryptoCode(ctx, filter, domain.SecretGeneratorTypeInitCode, alg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func userWriteModelByID(ctx context.Context, filter preparation.FilterToQueryReducer, userID, resourceOwner string) (*UserWriteModel, error) {
|
func userWriteModelByID(ctx context.Context, filter preparation.FilterToQueryReducer, userID, resourceOwner string) (*UserWriteModel, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user