feat: next
This commit is contained in:
49
server/internal/auth/creds.go
Normal file
49
server/internal/auth/creds.go
Normal file
@ -0,0 +1,49 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/spotdemo4/trevstack/server/internal/sqlc"
|
||||
)
|
||||
|
||||
func NewCreds(creds []sqlc.Credential) []webauthn.Credential {
|
||||
webauthnCreds := []webauthn.Credential{}
|
||||
|
||||
for _, c := range creds {
|
||||
transports := []protocol.AuthenticatorTransport{}
|
||||
if c.Transports != nil {
|
||||
for t := range strings.SplitSeq(*c.Transports, " ") {
|
||||
transports = append(transports, protocol.AuthenticatorTransport(t))
|
||||
}
|
||||
}
|
||||
|
||||
flags := webauthn.CredentialFlags{}
|
||||
if c.UserVerified != nil {
|
||||
flags.UserVerified = *c.UserVerified
|
||||
}
|
||||
if c.BackupEligible != nil {
|
||||
flags.BackupEligible = *c.BackupEligible
|
||||
}
|
||||
if c.BackupState != nil {
|
||||
flags.BackupState = *c.BackupState
|
||||
}
|
||||
|
||||
webauthnCreds = append(webauthnCreds, webauthn.Credential{
|
||||
ID: []byte(c.CredID),
|
||||
PublicKey: c.CredPublicKey,
|
||||
Authenticator: webauthn.Authenticator{
|
||||
SignCount: uint32(c.SignCount),
|
||||
},
|
||||
Transport: transports,
|
||||
Flags: flags,
|
||||
Attestation: webauthn.CredentialAttestation{
|
||||
Object: c.AttestationObject,
|
||||
ClientDataJSON: c.AttestationClientData,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return webauthnCreds
|
||||
}
|
33
server/internal/auth/user.go
Normal file
33
server/internal/auth/user.go
Normal file
@ -0,0 +1,33 @@
|
||||
package auth
|
||||
|
||||
import "github.com/go-webauthn/webauthn/webauthn"
|
||||
|
||||
type User struct {
|
||||
id string
|
||||
username string
|
||||
credentials []webauthn.Credential
|
||||
}
|
||||
|
||||
func NewUser(id string, username string, credentials []webauthn.Credential) User {
|
||||
return User{
|
||||
id: id,
|
||||
username: username,
|
||||
credentials: credentials,
|
||||
}
|
||||
}
|
||||
|
||||
func (u User) WebAuthnID() []byte {
|
||||
return []byte(u.id)
|
||||
}
|
||||
|
||||
func (u User) WebAuthnName() string {
|
||||
return u.username
|
||||
}
|
||||
|
||||
func (u User) WebAuthnDisplayName() string {
|
||||
return u.username
|
||||
}
|
||||
|
||||
func (u User) WebAuthnCredentials() []webauthn.Credential {
|
||||
return u.credentials
|
||||
}
|
Reference in New Issue
Block a user