Skip to content

Commit 98274a8

Browse files
authored
ClientAssertionCredential constructor fails if kwargs are provided (#33677)
* no need to call ABC.init * update * aio cac * update * black * add tests * update
1 parent 2923fe2 commit 98274a8

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

sdk/identity/azure-identity/CHANGELOG.md

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

99
### Bugs Fixed
1010

11+
- Fixed the bug that `ClientAssertionCredential` constructor fails if kwargs are provided. ([#33673](https://github.com/Azure/azure-sdk-for-python/issues/33673))
12+
1113
### Other Changes
1214

1315
## 1.15.0 (2023-10-26)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ class ClientAssertionCredential(GetTokenMixin):
4040

4141
def __init__(self, tenant_id: str, client_id: str, func: Callable[[], str], **kwargs: Any) -> None:
4242
self._func = func
43-
self._client = AadClient(tenant_id, client_id, **kwargs)
43+
authority = kwargs.pop("authority", None)
44+
cache = kwargs.pop("cache", None)
45+
cae_cache = kwargs.pop("cae_cache", None)
46+
additionally_allowed_tenants = kwargs.pop("additionally_allowed_tenants", None)
47+
self._client = AadClient(
48+
tenant_id,
49+
client_id,
50+
authority=authority,
51+
cache=cache,
52+
cae_cache=cae_cache,
53+
additionally_allowed_tenants=additionally_allowed_tenants,
54+
**kwargs
55+
)
4456
super(ClientAssertionCredential, self).__init__(**kwargs)
4557

4658
def __enter__(self):

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ class ClientAssertionCredential(AsyncContextManager, GetTokenMixin):
4040

4141
def __init__(self, tenant_id: str, client_id: str, func: Callable[[], str], **kwargs: Any) -> None:
4242
self._func = func
43-
self._client = AadClient(tenant_id, client_id, **kwargs)
43+
authority = kwargs.pop("authority", None)
44+
cache = kwargs.pop("cache", None)
45+
cae_cache = kwargs.pop("cae_cache", None)
46+
additionally_allowed_tenants = kwargs.pop("additionally_allowed_tenants", None)
47+
self._client = AadClient(
48+
tenant_id,
49+
client_id,
50+
authority=authority,
51+
cache=cache,
52+
cae_cache=cae_cache,
53+
additionally_allowed_tenants=additionally_allowed_tenants,
54+
**kwargs
55+
)
4456
super().__init__(**kwargs)
4557

4658
async def __aenter__(self):
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
from typing import Callable
6+
from azure.identity import ClientAssertionCredential
7+
8+
9+
def test_init_with_kwargs():
10+
tenant_id: str = "TENANT_ID"
11+
client_id: str = "CLIENT_ID"
12+
func: Callable[[], str] = lambda: "TOKEN"
13+
14+
credential: ClientAssertionCredential = ClientAssertionCredential(
15+
tenant_id=tenant_id, client_id=client_id, func=func, authority="a"
16+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
from typing import Callable
6+
from azure.identity.aio import ClientAssertionCredential
7+
8+
9+
def test_init_with_kwargs():
10+
tenant_id: str = "TENANT_ID"
11+
client_id: str = "CLIENT_ID"
12+
func: Callable[[], str] = lambda: "TOKEN"
13+
14+
credential: ClientAssertionCredential = ClientAssertionCredential(
15+
tenant_id=tenant_id, client_id=client_id, func=func, authority="a"
16+
)

0 commit comments

Comments
 (0)