From 24a3a0e35130c8aff480a0a2377d9d74b6f9b274 Mon Sep 17 00:00:00 2001 From: mijime <4719974+mijime@users.noreply.github.com> Date: Wed, 30 Jun 2021 00:06:18 +0900 Subject: [PATCH] feat: support refresh token (#30) --- v2/cmd/beareq-oapi/main.go | 1 + v2/cmd/beareq/main.go | 1 + v2/pkg/client/builder/client_builder.go | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/v2/cmd/beareq-oapi/main.go b/v2/cmd/beareq-oapi/main.go index ed0f856..1ba76d3 100644 --- a/v2/cmd/beareq-oapi/main.go +++ b/v2/cmd/beareq-oapi/main.go @@ -22,6 +22,7 @@ func main() { flag.StringVar(&cb.Profile, "profile", cb.Profile, "") flag.StringVar(&cb.ProfilesPath, "profiles", cb.ProfilesPath, "") flag.StringVar(&cb.TokenDir, "tokens", cb.TokenDir, "") + flag.BoolVar(&cb.RefreshToken, "refresh-token", cb.RefreshToken, "") rh := handler.NewResponseHandler() flag.Var(&rh.JSONQuery, "jq", "") diff --git a/v2/cmd/beareq/main.go b/v2/cmd/beareq/main.go index 1f0a32e..5764de7 100644 --- a/v2/cmd/beareq/main.go +++ b/v2/cmd/beareq/main.go @@ -16,6 +16,7 @@ func main() { flag.StringVar(&cb.Profile, "profile", cb.Profile, "") flag.StringVar(&cb.ProfilesPath, "profiles", cb.ProfilesPath, "") flag.StringVar(&cb.TokenDir, "tokens", cb.TokenDir, "") + flag.BoolVar(&cb.RefreshToken, "refresh-token", cb.RefreshToken, "") rb := rbuilder.NewRequestBuilder() flag.Var(&rb.Method, "request", "Specify request command to use") diff --git a/v2/pkg/client/builder/client_builder.go b/v2/pkg/client/builder/client_builder.go index 22cec2a..78fd269 100644 --- a/v2/pkg/client/builder/client_builder.go +++ b/v2/pkg/client/builder/client_builder.go @@ -25,6 +25,7 @@ type ClientBuilder struct { Profile string ProfilesPath string TokenDir string + RefreshToken bool } func osGetEnv(key string, defaultValue string) string { @@ -153,7 +154,7 @@ func (b *ClientBuilder) fetchToken(config *oauth2.Config) (*oauth2.Token, error) tokenPath := path.Join(b.TokenDir, b.Profile+".json") tokfp, err := os.Open(tokenPath) - if errors.Is(err, os.ErrNotExist) { + if b.RefreshToken || errors.Is(err, os.ErrNotExist) { return generateToken(config) }