2023-06-15 05:32:40 +00:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object/v2"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-09-13 12:43:01 +00:00
|
|
|
user "github.com/zitadel/zitadel/pkg/grpc/user/v2beta"
|
2023-06-15 05:32:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) RegisterU2F(ctx context.Context, req *user.RegisterU2FRequest) (*user.RegisterU2FResponse, error) {
|
|
|
|
return u2fRegistrationDetailsToPb(
|
2024-03-27 18:22:17 +00:00
|
|
|
s.command.RegisterUserU2F(ctx, req.GetUserId(), "", req.GetDomain()),
|
2023-06-15 05:32:40 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func u2fRegistrationDetailsToPb(details *domain.WebAuthNRegistrationDetails, err error) (*user.RegisterU2FResponse, error) {
|
|
|
|
objectDetails, options, err := webAuthNRegistrationDetailsToPb(details, err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &user.RegisterU2FResponse{
|
|
|
|
Details: objectDetails,
|
|
|
|
U2FId: details.ID,
|
|
|
|
PublicKeyCredentialCreationOptions: options,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) VerifyU2FRegistration(ctx context.Context, req *user.VerifyU2FRegistrationRequest) (*user.VerifyU2FRegistrationResponse, error) {
|
|
|
|
pkc, err := req.GetPublicKeyCredential().MarshalJSON()
|
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USERv2-IeTh4", "Errors.Internal")
|
2023-06-15 05:32:40 +00:00
|
|
|
}
|
2024-03-27 18:22:17 +00:00
|
|
|
objectDetails, err := s.command.HumanVerifyU2FSetup(ctx, req.GetUserId(), "", req.GetTokenName(), "", pkc)
|
2023-06-15 05:32:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &user.VerifyU2FRegistrationResponse{
|
|
|
|
Details: object.DomainToDetailsPb(objectDetails),
|
|
|
|
}, nil
|
|
|
|
}
|