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

79 lines
1.8 KiB
Go
Raw Permalink Normal View History

2024-08-12 11:00:25 +02:00
package model
import (
"database/sql/driver"
"encoding/json"
"time"
"github.com/go-webauthn/webauthn/protocol"
datatype "github.com/pocket-id/pocket-id/backend/internal/model/types"
2025-10-24 12:14:19 +02:00
"github.com/pocket-id/pocket-id/backend/internal/utils"
2024-08-12 11:00:25 +02:00
)
type WebauthnSession struct {
Base
Challenge string
ExpiresAt datatype.DateTime
2024-08-12 11:00:25 +02:00
UserVerification string
2025-10-24 12:14:19 +02:00
CredentialParams CredentialParameters
2024-08-12 11:00:25 +02:00
}
type WebauthnCredential struct {
Base
2024-08-23 17:04:19 +02:00
Name string
CredentialID []byte
2024-08-23 17:04:19 +02:00
PublicKey []byte
AttestationType string
Transport AuthenticatorTransportList
2024-08-12 11:00:25 +02:00
BackupEligible bool `json:"backupEligible"`
BackupState bool `json:"backupState"`
2024-08-12 11:00:25 +02:00
UserID string
}
type PublicKeyCredentialCreationOptions struct {
2024-08-23 17:04:19 +02:00
Response protocol.PublicKeyCredentialCreationOptions
SessionID string
Timeout time.Duration
}
type PublicKeyCredentialRequestOptions struct {
2024-08-23 17:04:19 +02:00
Response protocol.PublicKeyCredentialRequestOptions
SessionID string
Timeout time.Duration
}
type ReauthenticationToken struct {
Base
Token string
ExpiresAt datatype.DateTime
UserID string
User User
}
2025-03-27 16:48:36 +01:00
type AuthenticatorTransportList []protocol.AuthenticatorTransport //nolint:recvcheck
2024-08-12 11:00:25 +02:00
// Scan and Value methods for GORM to handle the custom type
func (atl *AuthenticatorTransportList) Scan(value interface{}) error {
2025-10-24 12:14:19 +02:00
return utils.UnmarshalJSONFromDatabase(atl, value)
2024-08-12 11:00:25 +02:00
}
func (atl AuthenticatorTransportList) Value() (driver.Value, error) {
return json.Marshal(atl)
}
2025-10-24 12:14:19 +02:00
type CredentialParameters []protocol.CredentialParameter //nolint:recvcheck
// Scan and Value methods for GORM to handle the custom type
func (cp *CredentialParameters) Scan(value interface{}) error {
return utils.UnmarshalJSONFromDatabase(cp, value)
}
func (cp CredentialParameters) Value() (driver.Value, error) {
return json.Marshal(cp)
}