Skip to content

Commit 80f64c7

Browse files
vhvb1989Copilot
andcommitted
fix: address review feedback from hemarina
- Add links field to AADSTS700082 error suggestion rule - Broaden login-state gate: only skip cleanup on ErrNoCurrentUser, proceed with cleanup for any other result (including corrupted cache) - Add telemetry attribute for cache-clear failures - Update test to verify links in AADSTS700082 rule Co-authored-by: Copilot <[email protected]>
1 parent c65807f commit 80f64c7

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

cli/azd/cmd/auth_login.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/azure/azure-dev/cli/azd/pkg/tools/github"
3434
"github.com/spf13/cobra"
3535
"github.com/spf13/pflag"
36+
"go.opentelemetry.io/otel/attribute"
3637
)
3738

3839
// The parent of the login command.
@@ -367,14 +368,17 @@ func (la *loginAction) Run(ctx context.Context) (*actions.ActionResult, error) {
367368
}
368369
}
369370

370-
// When already logged in, clear cached auth data before re-authenticating.
371-
// This prevents issues with stale MSAL tokens or corrupted credential cache files
372-
// that can cause AADSTS700082 errors even after a successful login.
373-
if _, err := la.authManager.LogInDetails(ctx); err == nil {
371+
// When already logged in (or when login state cannot be determined due to corrupted cache),
372+
// clear cached auth data before re-authenticating. This prevents issues with stale MSAL
373+
// tokens or corrupted credential cache files that can cause AADSTS700082 errors even after
374+
// a successful login. Only skip cleanup when definitively not logged in.
375+
if _, err := la.authManager.LogInDetails(ctx); !errors.Is(err, auth.ErrNoCurrentUser) {
374376
if err := la.authManager.CleanAllAuthCache(); err != nil {
377+
tracing.SetUsageAttributes(attribute.String("auth.cache_clear_failed", "auth"))
375378
return nil, fmt.Errorf("clearing auth cache: %w", err)
376379
}
377380
if err := la.accountSubManager.ClearSubscriptions(ctx); err != nil {
381+
tracing.SetUsageAttributes(attribute.String("auth.cache_clear_failed", "subscriptions"))
378382
return nil, fmt.Errorf("clearing subscriptions cache: %w", err)
379383
}
380384
}

cli/azd/pkg/errorhandler/pipeline_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ func TestErrorSuggestionsYaml_AADSTS700082_SpecificRule(t *testing.T) {
728728
assert.Equal(t, "The refresh token has expired or been revoked.", result.Message)
729729
assert.Contains(t, result.Suggestion, "azd auth login")
730730
assert.Contains(t, result.Suggestion, "automatically clears stale cached tokens")
731+
require.Len(t, result.Links, 1)
732+
assert.Contains(t, result.Links[0].URL, "azd-auth-login")
731733
}
732734

733735
func TestErrorSuggestionsYaml_AADSTS_GenericRule(t *testing.T) {

cli/azd/resources/error_suggestions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ rules:
611611
Run 'azd auth login' to sign in again.
612612
When already logged in, azd automatically clears stale cached tokens before
613613
re-authenticating.
614+
links:
615+
- url: "https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-auth-login"
616+
title: "azd auth login reference"
614617

615618
- patterns:
616619
- "AADSTS"

0 commit comments

Comments
 (0)