diff --git a/internal/handlers/handler_webauthn_devices.go b/internal/handlers/handler_webauthn_devices.go index 2fe2ce19d..ccc331ebd 100644 --- a/internal/handlers/handler_webauthn_devices.go +++ b/internal/handlers/handler_webauthn_devices.go @@ -9,6 +9,7 @@ import ( "github.com/authelia/authelia/v4/internal/middlewares" "github.com/authelia/authelia/v4/internal/regulation" + "github.com/authelia/authelia/v4/internal/storage" ) func getWebauthnDeviceIDFromContext(ctx *middlewares.AutheliaCtx) (int, error) { @@ -35,7 +36,7 @@ func WebauthnDevicesGet(ctx *middlewares.AutheliaCtx) { devices, err := ctx.Providers.StorageProvider.LoadWebauthnDevicesByUsername(ctx, userSession.Username) - if err != nil { + if err != nil && err != storage.ErrNoWebauthnDevice { ctx.Error(err, messageOperationFailed) return } diff --git a/internal/model/webauthn.go b/internal/model/webauthn.go index 534eba9d4..aa8b7a7f8 100644 --- a/internal/model/webauthn.go +++ b/internal/model/webauthn.go @@ -136,6 +136,22 @@ func NewWebauthnDeviceFromCredential(rpid, username, description string, credent return device } +// WebauthnDeviceJSON represents a Webauthn Device in the JSON format. +type WebauthnDeviceJSON struct { + ID int `json:"id"` + CreatedAt time.Time `json:"created_at"` + LastUsedAt *time.Time `json:"last_used_at,omitempty"` + RPID string `json:"rpid"` + Description string `json:"description"` + KID []byte `json:"kid"` + PublicKey []byte `json:"public_key"` + AttestationType string `json:"attestation_type"` + Transports []string `json:"transports"` + AAGUID string `json:"aaguid,omitempty"` + SignCount uint32 `json:"sign_count"` + CloneWarning bool `json:"clone_warning"` +} + // WebauthnDevice represents a Webauthn Device in the database storage. type WebauthnDevice struct { ID int `db:"id"` @@ -155,20 +171,7 @@ type WebauthnDevice struct { // MarshalJSON returns the WebauthnDevice in a JSON friendly manner. func (w *WebauthnDevice) MarshalJSON() (data []byte, err error) { - o := struct { - ID int `json:"id"` - CreatedAt time.Time `json:"created_at"` - LastUsedAt *time.Time `json:"last_used_at,omitempty"` - RPID string `json:"rpid"` - Description string `json:"description"` - KID []byte `json:"kid"` - PublicKey []byte `json:"public_key"` - AttestationType string `json:"attestation_type"` - Transports []string `json:"transports"` - AAGUID string `json:"aaguid,omitempty"` - SignCount uint32 `json:"sign_count"` - CloneWarning bool `json:"clone_warning"` - }{ + o := WebauthnDeviceJSON{ ID: w.ID, CreatedAt: w.CreatedAt, RPID: w.RPID, diff --git a/internal/storage/sql_provider.go b/internal/storage/sql_provider.go index 83675295c..b166398e1 100644 --- a/internal/storage/sql_provider.go +++ b/internal/storage/sql_provider.go @@ -941,7 +941,7 @@ func (p *SQLProvider) LoadWebauthnDevices(ctx context.Context, limit, page int) func (p *SQLProvider) LoadWebauthnDevicesByUsername(ctx context.Context, username string) (devices []model.WebauthnDevice, err error) { if err = p.db.SelectContext(ctx, &devices, p.sqlSelectWebauthnDevicesByUsername, username); err != nil { if errors.Is(err, sql.ErrNoRows) { - return nil, ErrNoWebauthnDevice + return devices, ErrNoWebauthnDevice } return nil, fmt.Errorf("error selecting Webauthn devices for user '%s': %w", username, err)