-
Notifications
You must be signed in to change notification settings - Fork 0
/
webauthnUser.go
59 lines (49 loc) · 1.23 KB
/
webauthnUser.go
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
package services
import (
"context"
"github.com/go-webauthn/webauthn/webauthn"
"github.com/juho05/h-id/repos"
"github.com/juho05/log"
)
type webAuthnUser struct {
user *repos.UserModel
credentials []webauthn.Credential
userRepo repos.UserRepository
}
func (a *authService) newWebAuthnUser(user *repos.UserModel) *webAuthnUser {
return &webAuthnUser{
user: user,
credentials: nil,
userRepo: a.userRepo,
}
}
func (w *webAuthnUser) loadCredentials() {
passkeys, err := w.userRepo.GetPasskeys(context.Background(), w.user.ID)
if err != nil {
w.credentials = make([]webauthn.Credential, 0)
log.Errorf("Failed to load webauthn credentials: %w", err)
return
}
w.credentials = make([]webauthn.Credential, len(passkeys))
for i, p := range passkeys {
w.credentials[i] = p.Credential
}
}
func (w *webAuthnUser) WebAuthnID() []byte {
return w.user.ID[:]
}
func (w *webAuthnUser) WebAuthnName() string {
return w.user.Email
}
func (w *webAuthnUser) WebAuthnDisplayName() string {
return w.user.Name
}
func (w *webAuthnUser) WebAuthnCredentials() []webauthn.Credential {
if w.credentials == nil {
w.loadCredentials()
}
return w.credentials
}
func (w *webAuthnUser) WebAuthnIcon() string {
return ""
}