fix: no webauthn devices doesn't display correctly (#4537)
* fix: no webauthn devices doesn't display correctly * refactor: factorizepull/4806/head
parent
326ed60a65
commit
67381b1318
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue