Skip to content

Commit ab5b4fb

Browse files
authored
AzureCLICredential respects application deadlines (Azure#19734)
1 parent 073769b commit ab5b4fb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sdk/azidentity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
### Bugs Fixed
1212

1313
### Other Changes
14+
* `AzureCLICredential` imposes its default timeout only when the `Context`
15+
passed to `GetToken()` has no deadline
1416

1517
## 1.3.0-beta.1 (2022-12-13)
1618

sdk/azidentity/azure_cli_credential.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ func defaultTokenProvider() func(ctx context.Context, resource string, tenantID
100100
return nil, fmt.Errorf(`%s: unexpected scope "%s". Only alphanumeric characters and ".", ";", "-", and "/" are allowed`, credNameAzureCLI, resource)
101101
}
102102

103-
ctx, cancel := context.WithTimeout(ctx, timeoutCLIRequest)
104-
defer cancel()
103+
// set a default timeout for this authentication iff the application hasn't done so already
104+
var cancel context.CancelFunc
105+
if _, hasDeadline := ctx.Deadline(); !hasDeadline {
106+
ctx, cancel = context.WithTimeout(ctx, timeoutCLIRequest)
107+
defer cancel()
108+
}
105109

106110
commandLine := "az account get-access-token -o json --resource " + resource
107111
if tenantID != "" {

0 commit comments

Comments
 (0)