Files
pocket-id/backend/internal/model/webauthn.go
T

44 lines
1.1 KiB
Go

package model
import (
"database/sql/driver"
"encoding/json"
"github.com/go-webauthn/webauthn/protocol"
"github.com/pocket-id/pocket-id/backend/internal/utils"
)
type WebauthnCredential struct {
Base
Name string
CredentialID []byte
PublicKey []byte
AttestationType string
Transport AuthenticatorTransportList
BackupEligible bool `json:"backupEligible"`
BackupState bool `json:"backupState"`
AAGUID string `gorm:"column:aaguid;default:00000000-0000-0000-0000-000000000000"`
UserID string
}
// HasIcon reports whether an icon is embedded for this credential's authenticator
// It is mapped onto the DTO so the frontend knows upfront whether an icon is worth requesting
func (c WebauthnCredential) HasIcon() bool {
return utils.HasAuthenticatorIcon(c.AAGUID)
}
type AuthenticatorTransportList []protocol.AuthenticatorTransport //nolint:recvcheck
// Scan and Value methods for GORM to handle the custom type
func (atl *AuthenticatorTransportList) Scan(value any) error {
return utils.UnmarshalJSONFromDatabase(atl, value)
}
func (atl AuthenticatorTransportList) Value() (driver.Value, error) {
return json.Marshal(atl)
}