lavender/auth/providers/passkey.go

51 lines
1.1 KiB
Go
Raw Normal View History

package providers
import (
"context"
2024-12-09 18:40:18 +00:00
"fmt"
"github.com/1f349/lavender/auth"
"github.com/1f349/lavender/database"
2024-12-09 18:40:18 +00:00
"html/template"
"net/http"
)
type passkeyLoginDB interface {
2024-12-09 18:40:18 +00:00
auth.LookupUserDB
}
var _ auth.Provider = (*PasskeyLogin)(nil)
type PasskeyLogin struct {
DB passkeyLoginDB
}
2024-12-09 18:40:18 +00:00
func (p *PasskeyLogin) AccessState() auth.State { return auth.StateUnauthorized }
func (p *PasskeyLogin) Name() string { return "passkey" }
2024-12-09 18:40:18 +00:00
func (p *PasskeyLogin) RenderTemplate(ctx context.Context, req *http.Request, user *database.User) (template.HTML, error) {
if user == nil || user.Subject == "" {
2024-12-09 18:40:18 +00:00
return "", fmt.Errorf("requires previous factor")
}
if user.OtpSecret == "" {
2024-12-09 18:40:18 +00:00
return "", fmt.Errorf("user does not support factor")
}
panic("implement me")
}
var passkeyShortcut = true
func init() {
passkeyShortcut = true
}
func (p *PasskeyLogin) AttemptLogin(ctx context.Context, req *http.Request, user *database.User) error {
if user.Subject == "" && !passkeyShortcut {
2024-12-09 18:40:18 +00:00
return fmt.Errorf("requires previous factor")
}
//TODO implement me
panic("implement me")
}