Skip to content

Commit

Permalink
Merge pull request #160 from Aloxaf/feat/verify_auth
Browse files Browse the repository at this point in the history
feat: add password verification for api-info command
  • Loading branch information
simlecode authored Oct 31, 2023
2 parents 1c0949a + ca9ad47 commit 2ba38f8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cli
import (
"errors"
"fmt"
"os"

"github.com/howeyc/gopass"
"github.com/urfave/cli/v2"

"github.com/ipfs-force-community/sophon-auth/core"
Expand Down Expand Up @@ -55,6 +57,24 @@ var authApiInfoToken = &cli.Command{
return fmt.Errorf("--perm flag has to be one of: %s", allPermissions)
}

if perm == core.PermAdmin || perm == core.PermSign {
api, closer, err := helper.GetFullAPI(cctx)
if err != nil {
return err
}
defer closer()

pw, err := gopass.GetPasswdPrompt("Password:", true, os.Stdin, os.Stdout)
if err != nil {
return err
}

ctx := helper.ReqContext(cctx)
if err := api.VerifyPassword(ctx, string(pw)); err != nil {
return err
}
}

// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
token, err := api.AuthNew(ctx, allPermissions[:idx])
if err != nil {
Expand Down

0 comments on commit 2ba38f8

Please sign in to comment.