2023-06-20 10:36:21 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
)
|
|
|
|
|
2023-06-22 10:06:32 +00:00
|
|
|
func (c *Commands) AddUserTOTP(ctx context.Context, userID, resourceowner string) (*domain.TOTP, error) {
|
2023-06-20 10:36:21 +00:00
|
|
|
if err := authz.UserIDInCTX(ctx, userID); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-06-22 10:06:32 +00:00
|
|
|
prep, err := c.createHumanTOTP(ctx, userID, resourceowner)
|
2023-06-20 10:36:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err = c.pushAppendAndReduce(ctx, prep.wm, prep.cmds...); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-06-22 10:06:32 +00:00
|
|
|
return &domain.TOTP{
|
2023-06-20 10:36:21 +00:00
|
|
|
ObjectDetails: writeModelToObjectDetails(&prep.wm.WriteModel),
|
|
|
|
Secret: prep.key.Secret(),
|
|
|
|
URI: prep.key.URL(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-06-22 10:06:32 +00:00
|
|
|
func (c *Commands) CheckUserTOTP(ctx context.Context, userID, code, resourceOwner string) (*domain.ObjectDetails, error) {
|
2023-06-20 10:36:21 +00:00
|
|
|
if err := authz.UserIDInCTX(ctx, userID); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return c.HumanCheckMFAOTPSetup(ctx, userID, code, "", resourceOwner)
|
|
|
|
}
|