2024-12-06 18:41:03 +00:00
|
|
|
package providers
|
2024-10-25 15:08:56 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-12-09 18:40:18 +00:00
|
|
|
"fmt"
|
2024-12-06 18:41:03 +00:00
|
|
|
"github.com/1f349/lavender/auth"
|
2024-10-25 15:08:56 +01:00
|
|
|
"github.com/1f349/lavender/database"
|
2024-12-09 18:40:18 +00:00
|
|
|
"html/template"
|
2024-10-25 15:08:56 +01:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type passkeyLoginDB interface {
|
2024-12-09 18:40:18 +00:00
|
|
|
auth.LookupUserDB
|
2024-10-25 15:08:56 +01:00
|
|
|
}
|
|
|
|
|
2024-12-06 18:41:03 +00:00
|
|
|
var _ auth.Provider = (*PasskeyLogin)(nil)
|
2024-10-25 15:08:56 +01:00
|
|
|
|
|
|
|
type PasskeyLogin struct {
|
|
|
|
DB passkeyLoginDB
|
|
|
|
}
|
|
|
|
|
2024-12-09 18:40:18 +00:00
|
|
|
func (p *PasskeyLogin) AccessState() auth.State { return auth.StateUnauthorized }
|
2024-10-25 15:08:56 +01:00
|
|
|
|
|
|
|
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) {
|
2024-10-25 15:08:56 +01:00
|
|
|
if user == nil || user.Subject == "" {
|
2024-12-09 18:40:18 +00:00
|
|
|
return "", fmt.Errorf("requires previous factor")
|
2024-10-25 15:08:56 +01:00
|
|
|
}
|
|
|
|
if user.OtpSecret == "" {
|
2024-12-09 18:40:18 +00:00
|
|
|
return "", fmt.Errorf("user does not support factor")
|
2024-10-25 15:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2024-10-25 15:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|