Skip to content

Commit

Permalink
feat: support refresh token (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
mijime committed Jun 29, 2021
1 parent 99493bb commit 24a3a0e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions v2/cmd/beareq-oapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
1 change: 1 addition & 0 deletions v2/cmd/beareq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion v2/pkg/client/builder/client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ClientBuilder struct {
Profile string
ProfilesPath string
TokenDir string
RefreshToken bool
}

func osGetEnv(key string, defaultValue string) string {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 24a3a0e

Please sign in to comment.