Skip to content

Commit 464c41d

Browse files
Copilotxiangyan99
andcommitted
Update error message format as requested - append claims after --ClaimsChallenge
Co-authored-by: xiangyan99 <[email protected]>
1 parent a5f2ae6 commit 464c41d

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

sdk/identity/azure-identity/azure/identity/_credentials/azure_powershell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_token(
139139
# Check if claims challenge is provided
140140
if claims:
141141
raise CredentialUnavailableError(
142-
message=f"Fail to get token with claims challenge '{claims}', please run Connect-AzAccount --ClaimsChallenge"
142+
message=f"Fail to get token, please run Connect-AzAccount --ClaimsChallenge {claims}"
143143
)
144144

145145
options: TokenRequestOptions = {}
@@ -180,7 +180,7 @@ def _get_token_base(
180180
if options and options.get("claims"):
181181
claims_value = options.get("claims")
182182
raise CredentialUnavailableError(
183-
message=f"Fail to get token with claims challenge '{claims_value}', please run Connect-AzAccount --ClaimsChallenge"
183+
message=f"Fail to get token, please run Connect-AzAccount --ClaimsChallenge {claims_value}"
184184
)
185185

186186
tenant_id = options.get("tenant_id") if options else None

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def get_token(
8484
# Check if claims challenge is provided
8585
if claims:
8686
raise CredentialUnavailableError(
87-
message=f"Fail to get token with claims challenge '{claims}', please run Connect-AzAccount --ClaimsChallenge"
87+
message=f"Fail to get token, please run Connect-AzAccount --ClaimsChallenge {claims}"
8888
)
8989

9090
# only ProactorEventLoop supports subprocesses on Windows (and it isn't the default loop on Python < 3.8)
@@ -124,7 +124,7 @@ async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptio
124124
if options and options.get("claims"):
125125
claims_value = options.get("claims")
126126
raise CredentialUnavailableError(
127-
message=f"Fail to get token with claims challenge '{claims_value}', please run Connect-AzAccount --ClaimsChallenge"
127+
message=f"Fail to get token, please run Connect-AzAccount --ClaimsChallenge {claims_value}"
128128
)
129129

130130
if sys.platform.startswith("win") and not isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop):
@@ -139,7 +139,7 @@ async def _get_token_base(
139139
if options and options.get("claims"):
140140
claims_value = options.get("claims")
141141
raise CredentialUnavailableError(
142-
message=f"Fail to get token with claims challenge '{claims_value}', please run Connect-AzAccount --ClaimsChallenge"
142+
message=f"Fail to get token, please run Connect-AzAccount --ClaimsChallenge {claims_value}"
143143
)
144144

145145
tenant_id = options.get("tenant_id") if options else None

sdk/identity/azure-identity/tests/test_powershell_credential.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ def test_claims_challenge_error(get_token_method):
390390
# Test claims parameter in get_token method
391391
with pytest.raises(CredentialUnavailableError) as exc_info:
392392
getattr(AzurePowerShellCredential(), get_token_method)("scope", claims="some-claims")
393-
assert "Fail to get token with claims challenge 'some-claims', please run Connect-AzAccount --ClaimsChallenge" in str(exc_info.value)
393+
assert "Fail to get token, please run Connect-AzAccount --ClaimsChallenge some-claims" in str(exc_info.value)
394394
else:
395395
# Test claims in options for get_token_info method
396396
with pytest.raises(CredentialUnavailableError) as exc_info:
397397
getattr(AzurePowerShellCredential(), get_token_method)("scope", options={"claims": "some-claims"})
398-
assert "Fail to get token with claims challenge 'some-claims', please run Connect-AzAccount --ClaimsChallenge" in str(exc_info.value)
398+
assert "Fail to get token, please run Connect-AzAccount --ClaimsChallenge some-claims" in str(exc_info.value)
399399

400400

401401
@pytest.mark.parametrize("get_token_method", GET_TOKEN_METHODS)

sdk/identity/azure-identity/tests/test_powershell_credential_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ async def test_claims_challenge_error(get_token_method):
399399
# Test claims parameter in get_token method
400400
with pytest.raises(CredentialUnavailableError) as exc_info:
401401
await getattr(AzurePowerShellCredential(), get_token_method)("scope", claims="some-claims")
402-
assert "Fail to get token with claims challenge 'some-claims', please run Connect-AzAccount --ClaimsChallenge" in str(exc_info.value)
402+
assert "Fail to get token, please run Connect-AzAccount --ClaimsChallenge some-claims" in str(exc_info.value)
403403
else:
404404
# Test claims in options for get_token_info method
405405
with pytest.raises(CredentialUnavailableError) as exc_info:
406406
await getattr(AzurePowerShellCredential(), get_token_method)("scope", options={"claims": "some-claims"})
407-
assert "Fail to get token with claims challenge 'some-claims', please run Connect-AzAccount --ClaimsChallenge" in str(exc_info.value)
407+
assert "Fail to get token, please run Connect-AzAccount --ClaimsChallenge some-claims" in str(exc_info.value)
408408

409409

410410
@pytest.mark.parametrize("get_token_method", GET_TOKEN_METHODS)

0 commit comments

Comments
 (0)