diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-12-27 13:34:56 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-12-27 13:37:47 -0800 |
| commit | 2a9faab3de7648344dcc1973a71ada8125c0afa3 (patch) | |
| tree | a6fd29a8d4ea62aaf17fdf214535dbdbb1c00d50 /tools/auth | |
| parent | 26235f94f87b01058cc06e69902f7fb30bffb22f (diff) | |
| download | roseh.moe-2a9faab3de7648344dcc1973a71ada8125c0afa3.tar.zst | |
Add Google Authenticator
Diffstat (limited to 'tools/auth')
| -rw-r--r-- | tools/auth/auth.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/auth/auth.go b/tools/auth/auth.go new file mode 100644 index 0000000..3c4f063 --- /dev/null +++ b/tools/auth/auth.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/base32" + "flag" + "fmt" + "os" + + "github.com/skip2/go-qrcode" + "roseh.moe/pkg/ccl" + "roseh.moe/pkg/roseh.moe/internal/config" +) + +func run() error { + args := flag.Args() + if len(args) != 1 { + return fmt.Errorf("usage: auth <config file>") + } + fileBytes, err := os.ReadFile(args[0]) + if err != nil { + return err + } + var config config.SecretsConfig + if err := ccl.Unmarshal(fileBytes, &config); err != nil { + return err + } + if len(config.AuthKey) == 0 { + return fmt.Errorf("%s: missing AuthKey", args[0]) + } + qrCode, err := qrcode.New(fmt.Sprintf("otpauth://totp/roseh.moe:rose?secret=%s&issuer=roseh.moe", base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(config.AuthKey)), qrcode.Medium) + if err != nil { + return err + } + fmt.Print(qrCode.ToSmallString(false)) + return nil +} + +func main() { + flag.Parse() + if err := run(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} |
