Skip to content

Commit

Permalink
use built-in context, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
joefitzgerald committed Sep 4, 2019
1 parent 03ff251 commit 9028364
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions passwordcredentials/passwordcredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,11 @@ import (
"strings"
"time"

"golang.org/x/net/context"
"context"

"golang.org/x/oauth2"
)

// tokenFromInternal maps an *internal.Token struct into
// an *oauth2.Token struct.
func tokenFromInternal(t *internalToken) *oauth2.Token {
if t == nil {
return nil
}
tk := &oauth2.Token{
AccessToken: t.AccessToken,
TokenType: t.TokenType,
RefreshToken: t.RefreshToken,
Expiry: t.Expiry,
}
return tk.WithExtra(t.Raw)
}

func retrieveToken(ctx context.Context, ClientID, ClientSecret, TokenURL string, v url.Values) (*oauth2.Token, error) {
hc := ContextClient(ctx)
v.Set("client_id", ClientID)
Expand All @@ -46,8 +32,8 @@ func retrieveToken(ctx context.Context, ClientID, ClientSecret, TokenURL string,
if err != nil {
return nil, err
}
defer r.Body.Close()
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1<<20))
r.Body.Close()
if err != nil {
return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err)
}
Expand Down

0 comments on commit 9028364

Please sign in to comment.