Skip to content

Commit

Permalink
Use library for refresh and password grants
Browse files Browse the repository at this point in the history
- library will return RequestErrors when appropriate

[#167636840]

Signed-off-by: Joshua Casey <[email protected]>
  • Loading branch information
andrewedstrom authored and joshuatcasey committed Sep 5, 2019
1 parent 53f7462 commit 2f8631f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
8 changes: 3 additions & 5 deletions cmd/get_password_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"code.cloudfoundry.org/uaa-cli/cli"
"code.cloudfoundry.org/uaa-cli/config"
"code.cloudfoundry.org/uaa-cli/help"
"context"
"errors"
"github.com/cloudfoundry-community/go-uaa"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)

func GetPasswordTokenValidations(cfg config.Config, args []string, username, password string) error {
Expand Down Expand Up @@ -46,12 +46,10 @@ func GetPasswordTokenCmd(cfg config.Config, clientId, clientSecret, username, pa
return errors.New("An error occurred while fetching token.")
}

transport := api.AuthenticatedClient.Transport.(*oauth2.Transport)
token, err := transport.Source.Token()

token, err := api.Token(context.Background())
if err != nil {
log.Info("Unable to retrieve token")
return uaa.RequestErrorFromOauthError(err)
return err
}

activeContext := cfg.GetActiveContext()
Expand Down
9 changes: 4 additions & 5 deletions cmd/refresh_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"code.cloudfoundry.org/uaa-cli/config"
"code.cloudfoundry.org/uaa-cli/help"
"code.cloudfoundry.org/uaa-cli/utils"
"context"
"errors"
"github.com/cloudfoundry-community/go-uaa"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)

func RefreshTokenCmd(cfg config.Config, log cli.Logger, tokenFormat string) error {
Expand All @@ -29,15 +29,14 @@ func RefreshTokenCmd(cfg config.Config, log cli.Logger, tokenFormat string) erro
)
log.Infof("Using the refresh_token from the active context to request a new access token for client %v.", utils.Emphasize(cfg.GetActiveContext().ClientId))
if err != nil {
return uaa.RequestErrorFromOauthError(err)
return err
}

ctx := cfg.GetActiveContext()

transport := api.AuthenticatedClient.Transport.(*oauth2.Transport)
token, err := transport.Source.Token()
token, err := api.Token(context.Background()) //TODO: stop making this request for a second time
if err != nil {
return uaa.RequestErrorFromOauthError(err)
return err
}

ctx.Token = *token
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module code.cloudfoundry.org/uaa-cli
go 1.12

require (
github.com/cloudfoundry-community/go-uaa v0.2.7
github.com/cloudfoundry-community/go-uaa v0.2.8
github.com/fatih/color v1.7.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-runewidth v0.0.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/cloudfoundry-community/go-uaa v0.2.7 h1:3M+b7JrzNcatZJwVnKXQeudkyosB1UPu4zI1VrDtmhc=
github.com/cloudfoundry-community/go-uaa v0.2.7/go.mod h1:5Cb7KTQLqX5Nn7cUd6ksPfnbfIp1g/j5Oo7nHeD0d3Q=
github.com/cloudfoundry-community/go-uaa v0.2.8 h1:jXRea4uJ8Bul5SABS4cqSZWuXPEw8e8EUyD5rqJp43E=
github.com/cloudfoundry-community/go-uaa v0.2.8/go.mod h1:5Cb7KTQLqX5Nn7cUd6ksPfnbfIp1g/j5Oo7nHeD0d3Q=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand Down

0 comments on commit 2f8631f

Please sign in to comment.