-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
ai foundIssues and Bugs that were found using AIIssues and Bugs that were found using AIbugSomething isn't workingSomething isn't working
Description
The GetTokenForScopes
method in auth.go
creates a new credential object for every call instead of reusing a single instance. This bypasses the internal token caching and renewal mechanisms provided by the Azure SDK (azidentity
), leading to unnecessary overhead from repeatedly initializing credentials.
Affected Code
The issue lies in the GetTokenForScopes
function and the authentication methods it calls (AuthenticateClientSecret
, AuthenticateUsingCli
, etc.). Each of these methods creates a new credential object unnecessarily.
Example from AuthenticateClientSecret
:
clientSecretCredential, err := azidentity.NewClientSecretCredential(...)
accessToken, err := clientSecretCredential.GetToken(ctx, policy.TokenRequestOptions{...})
This behavior is repeated in other methods like AuthenticateUsingCli
, AuthenticateClientCertificate
, etc.
Steps to Reproduce
- Call
GetTokenForScopes
multiple times in a short period with the same configuration (scopes, tenant ID, client ID, etc.). - Observe that new credential objects are created for each call, despite the configuration being consistent.
Expected Behavior
- Credential objects (e.g.,
ClientSecretCredential
,AzureCLICredential
) should be created once and reused across multiple calls toGetTokenForScopes
. - The Azure SDK's internal token caching and renewal mechanisms should handle token expiration and renewal automatically.
Actual Behavior
- A new credential object is instantiated for every call to
GetTokenForScopes
, bypassing the internal optimizations provided by the Azure SDK. - This results in unnecessary overhead from credential initialization.
Impact of fix
- Reduces unnecessary overhead from repeatedly creating credential objects.
- Improves efficiency and performance by leveraging the Azure SDK's built-in token caching and renewal mechanisms.
- Simplifies the implementation and avoids redundant instantiation of credentials.
Environment
- Repository: terraform-provider-power-platform
- File:
internal/api/auth.go
- Affected Method:
GetTokenForScopes
- Azure SDK Version: Confirmed to use
azidentity
andazcore
.
Additional Context
This issue was identified in the following file:
auth.go
Metadata
Metadata
Assignees
Labels
ai foundIssues and Bugs that were found using AIIssues and Bugs that were found using AIbugSomething isn't workingSomething isn't working