Files
Parham Alvani abf11609d8 feat(create): support passwordless / SSO login profiles (#3493)
Add a way to model accounts that have no stored password because login
happens through an external provider (e.g. Google, Apple, SSO).

- New default "SSO / passwordless login" wizard template that records the
  provider in a `login-method` field instead of prompting for a password.
- New `choice` attribute type so templates can offer a fixed list of
  options (used for the login-method provider picker).
- Optional passwords: a `password` attribute marked `optional: true` lets
  the user skip password entry, so a single template can serve both
  password and passwordless accounts.

The secret model already tolerates an empty password, so no changes to the
Secret interface or storage format are required.

Signed-off-by: Parham Alvani <parham.alvani@gmail.com>
2026-09-09 21:50:37 +02:00

133 lines
2.7 KiB
Go

package create
import (
"context"
"errors"
"fmt"
"github.com/gopasspw/gopass/internal/store"
"github.com/gopasspw/gopass/pkg/debug"
"go.yaml.in/yaml/v3"
)
var defaultTemplates = []string{
`---
priority: 0
name: "Website login"
prefix: "websites"
name_from:
- "url"
- "username"
welcome: "🧪 Creating Website login"
attributes:
- name: "url"
type: "hostname"
prompt: "Website URL"
min: 1
max: 255
- name: "username"
type: "string"
prompt: "Username"
min: 1
- name: "password"
type: "password"
prompt: "Password for the Website"
`,
`---
priority: 1
name: "PIN Code (numerical)"
prefix: "pin"
name_from:
- "authority"
- "application"
welcome: "🧪 Creating numerical PIN"
attributes:
- name: "authority"
type: "string"
prompt: "Authority"
min: 1
- name: "application"
type: "string"
prompt: "Entity"
min: 1
- name: "password"
type: "password"
prompt: "Pin"
charset: "0123456789"
min: 1
max: 64
- name: "comment"
type: "string"
`,
`---
priority: 2
name: "SSO / passwordless login (e.g. Google)"
prefix: "websites"
name_from:
- "url"
- "username"
welcome: "🧪 Creating SSO / passwordless login"
attributes:
- name: "url"
type: "hostname"
prompt: "Website URL"
min: 1
max: 255
- name: "username"
type: "string"
prompt: "Account / email"
min: 1
- name: "login-method"
type: "choice"
prompt: "Login via"
options:
- "google"
- "apple"
- "github"
- "microsoft"
- "sso"
- "magic-link"
- name: "comment"
type: "string"
`,
}
type storageSetter interface {
Set(context.Context, string, []byte) error
TryAdd(context.Context, ...string) error
TryCommit(context.Context, string) error
}
func (w *Wizard) writeTemplates(ctx context.Context, s storageSetter) error {
for _, y := range defaultTemplates {
by := []byte(y)
tpl := Template{}
if err := yaml.Unmarshal(by, &tpl); err != nil {
return fmt.Errorf("invalid default template. Please report a bug! %w", err)
}
path := fmt.Sprintf("%s%d-%s.yml", tplPath, tpl.Priority, tpl.Prefix)
if err := s.Set(ctx, path, by); err != nil {
if errors.Is(err, store.ErrMeaninglessWrite) {
debug.Log("got unexpected error for %s (ignoring): %s", path, err)
continue
}
return fmt.Errorf("failed to write default template %s: %w", path, err)
}
if err := s.TryAdd(ctx, path); err != nil {
return fmt.Errorf("failed to stage changes %s: %w", path, err)
}
debug.Log("wrote default template to %s", path)
}
if err := s.TryCommit(ctx, "Add default wizard templates"); err != nil {
return fmt.Errorf("failed to commit changes: %w", err)
}
return nil
}