48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package auth
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
|
|
"git.mstar.dev/mstar/goutils/other"
|
|
"github.com/go-webauthn/webauthn/protocol"
|
|
|
|
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
|
)
|
|
|
|
func (a *Authenticator) StartPasskeyLogin(username string) (*protocol.CredentialAssertion, error) {
|
|
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
wrappedAcc := fakeUser{acc}
|
|
options, session, err := a.webauthn.BeginLogin(&wrappedAcc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pkeySession := models.LoginProcessToken{
|
|
User: *acc,
|
|
UserId: acc.ID,
|
|
ExpiresAt: time.Now().Add(time.Minute * 3),
|
|
Token: string(other.Must(json.Marshal(session))),
|
|
}
|
|
err = dbgen.LoginProcessToken.Create(&pkeySession)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return options, nil
|
|
}
|
|
|
|
func (a *Authenticator) CompletePasskeyLogin(username string, response *http.Request) error {
|
|
panic("Not implemented") // TODO: Implement me
|
|
}
|
|
|
|
func (a *Authenticator) StartPasskeyRegistration(username string) error {
|
|
panic("Not implemented") // TODO: Implement me
|
|
}
|
|
|
|
func (a *Authenticator) CompletePasskeyRegistration(username string) error {
|
|
panic("Not implemented") // TODO: Implement me
|
|
}
|