generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
user.go
63 lines (51 loc) · 1.55 KB
/
user.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
60
61
62
63
package webauthn
import (
"github.com/go-webauthn/webauthn/protocol"
"github.com/go-webauthn/webauthn/webauthn"
)
type User struct {
ID string
FirstName string
LastName string
DisplayName string
Name string
Email string
WebauthnCredentials []webauthn.Credential `json:"-"`
}
var Sessions = map[string]*webauthn.SessionData{}
var Users = map[string]*User{}
// WebAuthnID is the user's webauthn ID
func (u *User) WebAuthnID() []byte {
return []byte(u.ID)
}
// WebAuthnName is the user's webauthn name
func (u *User) WebAuthnName() string {
return u.Name
}
// WebAuthnDisplayName is the user's webauthn display name
func (u *User) WebAuthnDisplayName() string {
if u.DisplayName != "" {
return u.DisplayName
}
return u.Name
}
// WebAuthnCredentials is the user's webauthn credentials
func (u *User) WebAuthnCredentials() []webauthn.Credential {
return u.WebauthnCredentials
}
// WebAuthnIcon is the user's webauthn icon
func (u *User) WebAuthnIcon() string {
return ""
}
// CredentialExcludeList returns a list of credentials to exclude from the webauthn credential list
func (u *User) CredentialExcludeList() []protocol.CredentialDescriptor {
credentialExcludeList := []protocol.CredentialDescriptor{}
for _, cred := range u.WebauthnCredentials {
descriptor := protocol.CredentialDescriptor{
Type: protocol.PublicKeyCredentialType,
CredentialID: cred.ID,
}
credentialExcludeList = append(credentialExcludeList, descriptor)
}
return credentialExcludeList
}