mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-17 05:18:04 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object/v2"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
user "github.com/zitadel/zitadel/pkg/grpc/user/v2beta"
|
|
)
|
|
|
|
func (s *Server) RegisterU2F(ctx context.Context, req *user.RegisterU2FRequest) (*user.RegisterU2FResponse, error) {
|
|
return u2fRegistrationDetailsToPb(
|
|
s.command.RegisterUserU2F(ctx, req.GetUserId(), authz.GetCtxData(ctx).OrgID, req.GetDomain()),
|
|
)
|
|
}
|
|
|
|
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) {
|
|
resourceOwner := authz.GetCtxData(ctx).OrgID
|
|
pkc, err := req.GetPublicKeyCredential().MarshalJSON()
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "USERv2-IeTh4", "Errors.Internal")
|
|
}
|
|
objectDetails, err := s.command.HumanVerifyU2FSetup(ctx, req.GetUserId(), resourceOwner, req.GetTokenName(), "", pkc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &user.VerifyU2FRegistrationResponse{
|
|
Details: object.DomainToDetailsPb(objectDetails),
|
|
}, nil
|
|
}
|