Skip to content

Commit 28184b0

Browse files
committed
Include context on deviceauth requests
1 parent 3e64809 commit 28184b0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

deviceauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func retrieveDeviceAuth(ctx context.Context, c *Config, v url.Values) (*DeviceAu
9898
return nil, errors.New("endpoint missing DeviceAuthURL")
9999
}
100100

101-
req, err := http.NewRequest("POST", c.Endpoint.DeviceAuthURL, strings.NewReader(v.Encode()))
101+
req, err := http.NewRequestWithContext(ctx, "POST", c.Endpoint.DeviceAuthURL, strings.NewReader(v.Encode()))
102102
if err != nil {
103103
return nil, err
104104
}

internal/token.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (c *AuthStyleCache) setAuthStyle(tokenURL string, v AuthStyle) {
180180
// as the POST body. An 'inParams' value of true means to send it in
181181
// the POST body (along with any values in v); false means to send it
182182
// in the Authorization header.
183-
func newTokenRequest(tokenURL, clientID, clientSecret string, v url.Values, authStyle AuthStyle) (*http.Request, error) {
183+
func newTokenRequest(ctx context.Context, tokenURL, clientID, clientSecret string, v url.Values, authStyle AuthStyle) (*http.Request, error) {
184184
if authStyle == AuthStyleInParams {
185185
v = cloneURLValues(v)
186186
if clientID != "" {
@@ -190,7 +190,7 @@ func newTokenRequest(tokenURL, clientID, clientSecret string, v url.Values, auth
190190
v.Set("client_secret", clientSecret)
191191
}
192192
}
193-
req, err := http.NewRequest("POST", tokenURL, strings.NewReader(v.Encode()))
193+
req, err := http.NewRequestWithContext(ctx, "POST", tokenURL, strings.NewReader(v.Encode()))
194194
if err != nil {
195195
return nil, err
196196
}
@@ -219,7 +219,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,
219219
authStyle = AuthStyleInHeader // the first way we'll try
220220
}
221221
}
222-
req, err := newTokenRequest(tokenURL, clientID, clientSecret, v, authStyle)
222+
req, err := newTokenRequest(ctx, tokenURL, clientID, clientSecret, v, authStyle)
223223
if err != nil {
224224
return nil, err
225225
}
@@ -238,7 +238,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,
238238
// they went, but maintaining it didn't scale & got annoying.
239239
// So just try both ways.
240240
authStyle = AuthStyleInParams // the second way we'll try
241-
req, _ = newTokenRequest(tokenURL, clientID, clientSecret, v, authStyle)
241+
req, _ = newTokenRequest(ctx, tokenURL, clientID, clientSecret, v, authStyle)
242242
token, err = doTokenRoundTrip(ctx, req)
243243
}
244244
if needsAuthStyleProbe && err == nil {

0 commit comments

Comments
 (0)