mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
|
package user
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
object "github.com/zitadel/zitadel/internal/api/grpc/object/v2beta"
|
||
|
"github.com/zitadel/zitadel/internal/domain"
|
||
|
user "github.com/zitadel/zitadel/pkg/grpc/user/v2beta"
|
||
|
)
|
||
|
|
||
|
func (s *Server) RegisterTOTP(ctx context.Context, req *user.RegisterTOTPRequest) (*user.RegisterTOTPResponse, error) {
|
||
|
return totpDetailsToPb(
|
||
|
s.command.AddUserTOTP(ctx, req.GetUserId(), ""),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
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) {
|
||
|
objectDetails, err := s.command.CheckUserTOTP(ctx, req.GetUserId(), req.GetCode(), "")
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &user.VerifyTOTPRegistrationResponse{
|
||
|
Details: object.DomainToDetailsPb(objectDetails),
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|