mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
# Which Problems Are Solved As part of going to a relation storage model, we need to implement the repository for handling sessions and their events. # How the Problems Are Solved - Adds a migration step to create the necessary tables and types in the database. - Adds the repository implementation for sessions. - Implements a projection handler for session events to handle the events written by the old command handlers. - Updates the `Session` type and `SessionRepository` interface: - added `CreatorID` - Adjusted `Delete` method to return amount of affected columns - Removed sub-repository clumns from the main interface - Added `CreatorIDCondition`, `ExpirationCondition`, `ExistsFactor` and `ExistsMetadata` - Removed `SetUserAgent` - Methods of `SessionFactor` and `SessionChallenge` have been made public - fixed enumer on `SessionFactorType` - Adds a `JSON` type to the repository package to easy can JSON columns, resp. jsonb object inside a property of a `JSONArray` object. - Adds a `NoChange` interface, which can be implemented to signal that a `Change` interface implementation is not writing any changes to the statement builder, e.g. `CTEChange` # Additional Changes - Fixes the operators enums. `TextOperations` had wrong comments and `NumberOperations` additionally also had from comparisons. - Fixes downgrade of migration step 008. # Additional Context - closes https://github.com/zitadel/zitadel/issues/10212
87 lines
2.6 KiB
Go
87 lines
2.6 KiB
Go
package webauthn
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/descope/virtualwebauthn"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
"google.golang.org/protobuf/types/known/structpb"
|
|
)
|
|
|
|
type Client struct {
|
|
rp virtualwebauthn.RelyingParty
|
|
auth virtualwebauthn.Authenticator
|
|
authVerifyUser virtualwebauthn.Authenticator
|
|
credential virtualwebauthn.Credential
|
|
}
|
|
|
|
func NewClient(name, domain, origin string) *Client {
|
|
rp := virtualwebauthn.RelyingParty{
|
|
Name: name,
|
|
ID: domain,
|
|
Origin: origin,
|
|
}
|
|
return &Client{
|
|
rp: rp,
|
|
auth: virtualwebauthn.NewAuthenticatorWithOptions(virtualwebauthn.AuthenticatorOptions{
|
|
UserNotVerified: true,
|
|
}),
|
|
authVerifyUser: virtualwebauthn.NewAuthenticator(),
|
|
credential: virtualwebauthn.NewCredential(virtualwebauthn.KeyTypeEC2),
|
|
}
|
|
}
|
|
|
|
func (c *Client) CreateAttestationResponse(optionsPb *structpb.Struct) (*structpb.Struct, error) {
|
|
options, err := protojson.Marshal(optionsPb)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("webauthn.Client.CreateAttestationResponse: %w", err)
|
|
}
|
|
attestationResponse, err := c.CreateAttestationResponseData(options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp := new(structpb.Struct)
|
|
err = protojson.Unmarshal(attestationResponse, resp)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("webauthn.Client.CreateAttestationResponse: %w", err)
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (c *Client) CreateAttestationResponseData(options []byte) ([]byte, error) {
|
|
parsedAttestationOptions, err := virtualwebauthn.ParseAttestationOptions(string(options))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("webauthn.Client.CreateAttestationResponse: %w", err)
|
|
}
|
|
return []byte(virtualwebauthn.CreateAttestationResponse(
|
|
c.rp, c.auth, c.credential, *parsedAttestationOptions,
|
|
)), nil
|
|
}
|
|
|
|
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)
|
|
}
|
|
parsedAssertionOptions, err := virtualwebauthn.ParseAssertionOptions(string(options))
|
|
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, authenticator, c.credential, *parsedAssertionOptions,
|
|
)), resp)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("webauthn.Client.CreateAssertionResponse: %w", err)
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (c *Client) KeyID() []byte {
|
|
return c.credential.ID
|
|
}
|