lavender/auth/providers/passkey.go

64 lines
1.3 KiB
Go
Raw Normal View History

package providers
import (
"context"
2024-12-09 18:40:18 +00:00
"fmt"
"github.com/1f349/lavender/auth"
2025-01-19 12:04:25 +00:00
"github.com/1f349/lavender/auth/authContext"
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
}
2025-01-19 12:04:25 +00:00
var (
_ auth.Provider = (*PasskeyLogin)(nil)
_ auth.Button = (*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" }
2025-01-19 12:04:25 +00:00
func (p *PasskeyLogin) RenderTemplate(ctx authContext.TemplateContext) error {
user := ctx.User()
if user == nil || user.Subject == "" {
2025-01-19 12:04:25 +00:00
return fmt.Errorf("requires previous factor")
}
if user.OtpSecret == "" {
2025-01-19 12:04:25 +00:00
return fmt.Errorf("user does not support factor")
}
panic("implement me")
}
var passkeyShortcut = true
func init() {
passkeyShortcut = true
}
2025-01-19 12:04:25 +00:00
func (p *PasskeyLogin) AttemptLogin(ctx authContext.TemplateContext) error {
user := ctx.User()
if user.Subject == "" && !passkeyShortcut {
2024-12-09 18:40:18 +00:00
return fmt.Errorf("requires previous factor")
}
//TODO implement me
panic("implement me")
}
2025-01-19 12:04:25 +00:00
func (p *PasskeyLogin) ButtonName() string {
return "Login with Passkey"
}
func (p *PasskeyLogin) RenderButtonTemplate(ctx context.Context, req *http.Request) template.HTML {
return "<div>Passkey Button</div>"
}