Skip to content

Commit e432a89

Browse files
authored
[Core] Enable CAE in auth policy by default (#42941)
CAE claims challenges have long been supported in our auth policies. This enables it by default. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 77a3f8a commit e432a89

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

sdk/core/azure-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Other Changes
1212

13+
- Updated `BearerTokenCredentialPolicy` and `AsyncBearerTokenCredentialPolicy` to set the `enable_cae` parameter to `True` by default. This change enables Continuous Access Evaluation (CAE) for all token requests made through these policies. #42941
14+
1315
## 1.35.1 (2025-09-11)
1416

1517
### Bugs Fixed

sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class _BearerTokenCredentialPolicyBase:
4545
:type credential: ~azure.core.credentials.TokenProvider
4646
:param str scopes: Lets you specify the type of access needed.
4747
:keyword bool enable_cae: Indicates whether to enable Continuous Access Evaluation (CAE) on all requested
48-
tokens. Defaults to False.
48+
tokens. Defaults to True.
4949
"""
5050

5151
def __init__(self, credential: TokenProvider, *scopes: str, **kwargs: Any) -> None:
5252
super(_BearerTokenCredentialPolicyBase, self).__init__()
5353
self._scopes = scopes
5454
self._credential = credential
5555
self._token: Optional[Union["AccessToken", "AccessTokenInfo"]] = None
56-
self._enable_cae: bool = kwargs.get("enable_cae", False)
56+
self._enable_cae: bool = kwargs.get("enable_cae", True)
5757

5858
@staticmethod
5959
def _enforce_https(request: PipelineRequest[HTTPRequestType]) -> None:

sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AsyncBearerTokenCredentialPolicy(AsyncHTTPPolicy[HTTPRequestType, AsyncHTT
4040
:type credential: ~azure.core.credentials_async.AsyncTokenProvider
4141
:param str scopes: Lets you specify the type of access needed.
4242
:keyword bool enable_cae: Indicates whether to enable Continuous Access Evaluation (CAE) on all requested
43-
tokens. Defaults to False.
43+
tokens. Defaults to True.
4444
"""
4545

4646
def __init__(self, credential: AsyncTokenProvider, *scopes: str, **kwargs: Any) -> None:
@@ -49,7 +49,7 @@ def __init__(self, credential: AsyncTokenProvider, *scopes: str, **kwargs: Any)
4949
self._scopes = scopes
5050
self._lock_instance = None
5151
self._token: Optional[Union["AccessToken", "AccessTokenInfo"]] = None
52-
self._enable_cae: bool = kwargs.get("enable_cae", False)
52+
self._enable_cae: bool = kwargs.get("enable_cae", True)
5353

5454
@property
5555
def _lock(self):

sdk/core/azure-core/tests/async_tests/test_authentication_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def test_bearer_policy_authorize_request(http_request):
7474
assert http_req.headers["Authorization"] == f"Bearer {expected_token.token}"
7575
assert fake_credential.get_token.call_count == 1
7676
assert fake_credential.get_token.call_args[0] == ("scope",)
77-
assert fake_credential.get_token.call_args[1] == {"claims": "foo"}
77+
assert fake_credential.get_token.call_args[1] == {"claims": "foo", "enable_cae": True}
7878

7979

8080
@pytest.mark.asyncio
@@ -132,7 +132,7 @@ async def test_bearer_policy_authorize_request_access_token_info(http_request):
132132
assert policy._token is expected_token
133133
assert http_req.headers["Authorization"] == f"Bearer {expected_token.token}"
134134
assert fake_credential.get_token_info.call_args[0] == ("scope",)
135-
assert fake_credential.get_token_info.call_args[1] == {"options": {"claims": "foo"}}
135+
assert fake_credential.get_token_info.call_args[1] == {"options": {"claims": "foo", "enable_cae": True}}
136136

137137

138138
@pytest.mark.asyncio

sdk/core/azure-core/tests/test_authentication.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_bearer_policy_authorize_request(http_request):
7474
assert http_req.headers["Authorization"] == f"Bearer {expected_token.token}"
7575
assert fake_credential.get_token.call_count == 1
7676
assert fake_credential.get_token.call_args[0] == ("scope",)
77-
assert fake_credential.get_token.call_args[1] == {"claims": "foo"}
77+
assert fake_credential.get_token.call_args[1] == {"claims": "foo", "enable_cae": True}
7878

7979

8080
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
@@ -119,7 +119,7 @@ def test_bearer_policy_authorize_request_access_token_info(http_request):
119119
assert policy._token is expected_token
120120
assert http_req.headers["Authorization"] == f"Bearer {expected_token.token}"
121121
assert fake_credential.get_token_info.call_args[0] == ("scope",)
122-
assert fake_credential.get_token_info.call_args[1] == {"options": {"claims": "foo"}}
122+
assert fake_credential.get_token_info.call_args[1] == {"options": {"claims": "foo", "enable_cae": True}}
123123

124124

125125
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
@@ -263,7 +263,7 @@ def test_bearer_policy_default_context(http_request):
263263

264264
pipeline.run(http_request("GET", "https://localhost"))
265265

266-
credential.get_token.assert_called_once_with(expected_scope)
266+
credential.get_token.assert_called_once_with(expected_scope, enable_cae=True)
267267

268268

269269
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)
@@ -333,7 +333,7 @@ def test_bearer_policy_cannot_complete_challenge(http_request):
333333

334334
assert response.http_response is expected_response
335335
assert transport.send.call_count == 1
336-
credential.get_token.assert_called_once_with(expected_scope)
336+
credential.get_token.assert_called_once_with(expected_scope, enable_cae=True)
337337

338338

339339
@pytest.mark.parametrize("http_request", HTTP_REQUESTS)

0 commit comments

Comments
 (0)