2023-06-22 10:06:32 +00:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object/v2"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2024-07-26 20:39:55 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
2023-06-22 10:06:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) RegisterTOTP(ctx context.Context, req *user.RegisterTOTPRequest) (*user.RegisterTOTPResponse, error) {
|
|
|
|
return totpDetailsToPb(
|
2024-03-27 18:22:17 +00:00
|
|
|
s.command.AddUserTOTP(ctx, req.GetUserId(), ""),
|
2023-06-22 10:06:32 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func totpDetailsToPb(totp *domain.TOTP, err error) (*user.RegisterTOTPResponse, error) {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &user.RegisterTOTPResponse{
|
|
|
|
Details: object.DomainToDetailsPb(totp.ObjectDetails),
|
|
|
|
Uri: totp.URI,
|
|
|
|
Secret: totp.Secret,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) VerifyTOTPRegistration(ctx context.Context, req *user.VerifyTOTPRegistrationRequest) (*user.VerifyTOTPRegistrationResponse, error) {
|
2024-03-27 18:22:17 +00:00
|
|
|
objectDetails, err := s.command.CheckUserTOTP(ctx, req.GetUserId(), req.GetCode(), "")
|
2023-06-22 10:06:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &user.VerifyTOTPRegistrationResponse{
|
|
|
|
Details: object.DomainToDetailsPb(objectDetails),
|
|
|
|
}, nil
|
|
|
|
}
|
2024-07-10 12:31:28 +00:00
|
|
|
|
|
|
|
func (s *Server) RemoveTOTP(ctx context.Context, req *user.RemoveTOTPRequest) (*user.RemoveTOTPResponse, error) {
|
|
|
|
objectDetails, err := s.command.HumanRemoveTOTP(ctx, req.GetUserId(), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &user.RemoveTOTPResponse{Details: object.DomainToDetailsPb(objectDetails)}, nil
|
|
|
|
}
|