mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:47:33 +00:00
feat(api/v2): implement U2F session check (#6339)
This commit is contained in:
@@ -9,9 +9,10 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
rp virtualwebauthn.RelyingParty
|
||||
auth virtualwebauthn.Authenticator
|
||||
credential virtualwebauthn.Credential
|
||||
rp virtualwebauthn.RelyingParty
|
||||
auth virtualwebauthn.Authenticator
|
||||
authVerifyUser virtualwebauthn.Authenticator
|
||||
credential virtualwebauthn.Credential
|
||||
}
|
||||
|
||||
func NewClient(name, domain, origin string) *Client {
|
||||
@@ -21,9 +22,12 @@ func NewClient(name, domain, origin string) *Client {
|
||||
Origin: origin,
|
||||
}
|
||||
return &Client{
|
||||
rp: rp,
|
||||
auth: virtualwebauthn.NewAuthenticator(),
|
||||
credential: virtualwebauthn.NewCredential(virtualwebauthn.KeyTypeEC2),
|
||||
rp: rp,
|
||||
auth: virtualwebauthn.NewAuthenticatorWithOptions(virtualwebauthn.AuthenticatorOptions{
|
||||
UserNotVerified: true,
|
||||
}),
|
||||
authVerifyUser: virtualwebauthn.NewAuthenticator(),
|
||||
credential: virtualwebauthn.NewCredential(virtualwebauthn.KeyTypeEC2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +50,7 @@ func (c *Client) CreateAttestationResponse(optionsPb *structpb.Struct) (*structp
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateAssertionResponse(optionsPb *structpb.Struct) (*structpb.Struct, error) {
|
||||
func (c *Client) CreateAssertionResponse(optionsPb *structpb.Struct, verifyUser bool) (*structpb.Struct, error) {
|
||||
options, err := protojson.Marshal(optionsPb)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("webauthn.Client.CreateAssertionResponse: %w", err)
|
||||
@@ -55,9 +59,13 @@ func (c *Client) CreateAssertionResponse(optionsPb *structpb.Struct) (*structpb.
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("webauthn.Client.CreateAssertionResponse: %w", err)
|
||||
}
|
||||
authenticator := c.auth
|
||||
if verifyUser {
|
||||
authenticator = c.authVerifyUser
|
||||
}
|
||||
resp := new(structpb.Struct)
|
||||
err = protojson.Unmarshal([]byte(virtualwebauthn.CreateAssertionResponse(
|
||||
c.rp, c.auth, c.credential, *parsedAssertionOptions,
|
||||
c.rp, authenticator, c.credential, *parsedAssertionOptions,
|
||||
)), resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("webauthn.Client.CreateAssertionResponse: %w", err)
|
||||
|
Reference in New Issue
Block a user