blob: 5c9ec90f9c9ddb3d00059ddafc2ab1bc1563a140 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package models
import (
"context"
"time"
"github.com/go-webauthn/webauthn/webauthn"
)
type User struct {
Username string `bson:"_id"`
DisplayName string
AllowedHosts []string
Fido2Credentials []webauthn.Credential
Deleted *time.Time
}
var _ webauthn.User = (*User)(nil)
func (u *User) RecordId() string {
return u.Username
}
func (u *User) MarkDeleted(t time.Time) {
u.Deleted = &t
}
func (u *User) WebAuthnID() []byte {
return []byte(u.Username)
}
func (u *User) WebAuthnName() string {
return u.Username
}
func (u *User) WebAuthnDisplayName() string {
return u.DisplayName
}
func (u *User) WebAuthnCredentials() []webauthn.Credential {
return u.Fido2Credentials
}
func (u *User) WebAuthnIcon() string {
return ""
}
func (u *User) AuthorizedForHost(host string) bool {
for _, c := range u.AllowedHosts {
if host == c {
return true
}
}
return false
}
type UserStore interface {
List(ctx context.Context) ([]*User, error)
ListAll(ctx context.Context) ([]*User, error)
Get(ctx context.Context, name string) (*User, error)
Upsert(ctx context.Context, m *User) error
Delete(ctx context.Context, m *User) error
}
|