Skip to content

Commit bd9a0ce

Browse files
xiangyan99scbeddmccoyp
authored
address review feedback (Azure#21109)
* address review feedback * update * update * update * crypto 35.0.0 is not compatible with our tests, pin in the dev_requirements * filter packages pinned in dev_reqs OUT of the results when installing during dependency testing * update * adjust check in install_depend_packages.py that was accidentally succeeding because of auto-trimming provided by py3. the check is actually doing the intended thing now. * update * Update sdk/identity/azure-identity/azure/identity/_credentials/on_behalf_of.py Co-authored-by: McCoy Patiño <[email protected]> * update * update * update Co-authored-by: scbedd <[email protected]> Co-authored-by: McCoy Patiño <[email protected]>
1 parent cb90cde commit bd9a0ce

17 files changed

+112
-77
lines changed

eng/tox/install_depend_packages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def filter_dev_requirements(setup_py_path, released_packages, temp_dir):
140140
filtered_req = [
141141
req
142142
for req in requirements
143-
if os.path.basename(req.replace('\n', '')) not in req_to_exclude
143+
if os.path.basename(req.replace('\n', '')) not in req_to_exclude and not any([req.startswith(i) for i in req_to_exclude])
144144
]
145145

146146
logging.info("Filtered dev requirements: %s", filtered_req)

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 1.7.0b5 (Unreleased)
3+
## 1.7.0 (2021-10-12)
44

55
### Breaking Changes
66
> These changes do not impact the API of stable versions such as 1.6.0.
@@ -10,7 +10,10 @@
1010
The multitenant authentication feature can be totally disabled by setting the environment variable
1111
`AZURE_IDENTITY_DISABLE_MULTITENANTAUTH` to `True`.
1212
- `azure.identity.RegionalAuthority` is removed.
13-
- `regional_authority` argument is removed for `CertificateCredential` and `ClientSecretCredential`
13+
- `regional_authority` argument is removed for `CertificateCredential` and `ClientSecretCredential`.
14+
- `AzureApplicationCredential` is removed.
15+
- `client_credential` in the ctor of `OnBehalfOfCredential` is removed. Please use `client_secret` or `client_certificate` instead.
16+
- Make `user_assertion` in the ctor of `OnBehalfOfCredential` a keyword only argument.
1417

1518
## 1.7.0b4 (2021-09-09)
1619

sdk/identity/azure-identity/azure/identity/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from ._constants import AzureAuthorityHosts, KnownAuthorities
1010
from ._credentials import (
1111
AuthorizationCodeCredential,
12-
AzureApplicationCredential,
1312
AzureCliCredential,
1413
AzurePowerShellCredential,
1514
CertificateCredential,
@@ -32,7 +31,6 @@
3231
"AuthenticationRecord",
3332
"AuthenticationRequiredError",
3433
"AuthorizationCodeCredential",
35-
"AzureApplicationCredential",
3634
"AzureAuthorityHosts",
3735
"AzureCliCredential",
3836
"AzurePowerShellCredential",

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5-
from .application import AzureApplicationCredential
65
from .authorization_code import AuthorizationCodeCredential
76
from .azure_powershell import AzurePowerShellCredential
87
from .browser import InteractiveBrowserCredential
@@ -22,7 +21,6 @@
2221

2322
__all__ = [
2423
"AuthorizationCodeCredential",
25-
"AzureApplicationCredential",
2624
"AzureCliCredential",
2725
"AzurePowerShellCredential",
2826
"CertificateCredential",

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

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License.
44
# ------------------------------------
55
import time
6-
from typing import cast, TYPE_CHECKING
6+
from typing import TYPE_CHECKING
77

88
import six
99

@@ -33,42 +33,50 @@ class OnBehalfOfCredential(MsalCredential, GetTokenMixin):
3333
3434
:param str tenant_id: ID of the service principal's tenant. Also called its "directory" ID.
3535
:param str client_id: the service principal's client ID
36-
:param client_credential: a credential to authenticate the service principal, either one of its client secrets (a
37-
string) or the bytes of a certificate in PEM or PKCS12 format including the private key
38-
:type client_credential: str or bytes
39-
:param str user_assertion: the access token the credential will use as the user assertion when requesting
40-
on-behalf-of tokens
36+
:keyword str client_secret: Optional. A client secret to authenticate the service principal.
37+
Either **client_secret** or **client_certificate** must be provided.
38+
:keyword bytes client_certificate: Optional. The bytes of a certificate in PEM or PKCS12 format including
39+
the private key to authenticate the service principal. Either **client_secret** or **client_certificate** must
40+
be provided.
41+
:keyword str user_assertion: Required. The access token the credential will use as the user assertion when
42+
requesting on-behalf-of tokens
4143
4244
:keyword str authority: Authority of an Azure Active Directory endpoint, for example "login.microsoftonline.com",
4345
the authority for Azure Public Cloud (which is the default). :class:`~azure.identity.AzureAuthorityHosts`
4446
defines authorities for other clouds.
45-
:keyword password: a certificate password. Used only when **client_credential** is certificate bytes. If this value
47+
:keyword password: a certificate password. Used only when **client_certificate** is provided. If this value
4648
is a unicode string, it will be encoded as UTF-8. If the certificate requires a different encoding, pass
4749
appropriately encoded bytes instead.
4850
:paramtype password: str or bytes
4951
"""
5052

51-
def __init__(self, tenant_id, client_id, client_credential, user_assertion, **kwargs):
52-
# type: (str, str, Union[bytes, str], str, **Any) -> None
53-
credential = cast("Union[Dict, str]", client_credential)
54-
if isinstance(client_credential, six.binary_type):
53+
def __init__(self, tenant_id, client_id, **kwargs):
54+
# type: (str, str, **Any) -> None
55+
self._assertion = kwargs.pop("user_assertion", None)
56+
if not self._assertion:
57+
raise TypeError('"user_assertion" is required.')
58+
client_certificate = kwargs.pop("client_certificate", None)
59+
client_secret = kwargs.pop("client_secret", None)
60+
61+
if client_certificate:
62+
if client_secret:
63+
raise ValueError('Specifying both "client_certificate" and "client_secret" is not valid.')
5564
try:
5665
credential = get_client_credential(
57-
certificate_path=None, password=kwargs.pop("password", None), certificate_data=client_credential
66+
certificate_path=None, password=kwargs.pop("password", None), certificate_data=client_certificate
5867
)
5968
except ValueError as ex:
60-
# client_credential isn't a valid cert. On 2.7 str == bytes and we ignore this exception because we
61-
# can't tell whether the caller intended to provide a cert. On Python 3 we can say the caller provided
62-
# either an invalid cert, or a client secret as bytes; both are errors.
63-
if six.PY3:
64-
message = (
65-
'"client_credential" should be either a client secret (a string)'
66-
+ " or the bytes of a certificate in PEM or PKCS12 format"
67-
)
68-
six.raise_from(ValueError(message), ex)
69+
# client_certificate isn't a valid cert.
70+
message = (
71+
'"client_certificate" is not a valid certificate in PEM or PKCS12 format'
72+
)
73+
six.raise_from(ValueError(message), ex)
74+
elif client_secret:
75+
credential = client_secret
76+
else:
77+
raise TypeError('Either "client_certificate" or "client_secret" must be provided')
6978

7079
super(OnBehalfOfCredential, self).__init__(client_id, credential, tenant_id=tenant_id, **kwargs)
71-
self._assertion = user_assertion
7280
self._auth_record = None # type: Optional[AuthenticationRecord]
7381

7482
@wrap_exceptions

sdk/identity/azure-identity/azure/identity/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5-
VERSION = "1.7.0b5"
5+
VERSION = "1.7.0"

sdk/identity/azure-identity/azure/identity/aio/__init__.py

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

77
from ._credentials import (
88
AuthorizationCodeCredential,
9-
AzureApplicationCredential,
109
AzureCliCredential,
1110
AzurePowerShellCredential,
1211
CertificateCredential,
@@ -23,7 +22,6 @@
2322

2423
__all__ = [
2524
"AuthorizationCodeCredential",
26-
"AzureApplicationCredential",
2725
"AzureCliCredential",
2826
"AzurePowerShellCredential",
2927
"CertificateCredential",

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5-
from .application import AzureApplicationCredential
65
from .authorization_code import AuthorizationCodeCredential
76
from .azure_powershell import AzurePowerShellCredential
87
from .chained import ChainedTokenCredential
@@ -19,7 +18,6 @@
1918

2019
__all__ = [
2120
"AuthorizationCodeCredential",
22-
"AzureApplicationCredential",
2321
"AzureCliCredential",
2422
"AzurePowerShellCredential",
2523
"CertificateCredential",

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ class OnBehalfOfCredential(AsyncContextManager, GetTokenMixin):
3030
3131
:param str tenant_id: ID of the service principal's tenant. Also called its "directory" ID.
3232
:param str client_id: the service principal's client ID
33-
:param client_credential: a credential to authenticate the service principal, either one of its client secrets (a
34-
string) or the bytes of a certificate in PEM or PKCS12 format including the private key
35-
:paramtype client_credential: str or bytes
36-
:param str user_assertion: the access token the credential will use as the user assertion when requesting
37-
on-behalf-of tokens
33+
:keyword str client_secret: Optional. A client secret to authenticate the service principal.
34+
Either **client_secret** or **client_certificate** must be provided.
35+
:keyword bytes client_certificate: Optional. The bytes of a certificate in PEM or PKCS12 format including
36+
the private key to authenticate the service principal. Either **client_secret** or **client_certificate** must
37+
be provided.
38+
:keyword str user_assertion: Required. The access token the credential will use as the user assertion when
39+
requesting on-behalf-of tokens
3840
3941
:keyword str authority: Authority of an Azure Active Directory endpoint, for example "login.microsoftonline.com",
4042
the authority for Azure Public Cloud (which is the default). :class:`~azure.identity.AzureAuthorityHosts`
4143
defines authorities for other clouds.
42-
:keyword password: a certificate password. Used only when **client_credential** is certificate bytes. If this value
44+
:keyword password: a certificate password. Used only when **client_certificate** is provided. If this value
4345
is a unicode string, it will be encoded as UTF-8. If the certificate requires a different encoding, pass
4446
appropriately encoded bytes instead.
4547
:paramtype password: str or bytes
@@ -49,31 +51,37 @@ def __init__(
4951
self,
5052
tenant_id: str,
5153
client_id: str,
52-
client_credential: "Union[bytes, str]",
54+
*,
55+
client_certificate: bytes = None,
56+
client_secret: str = None,
5357
user_assertion: str,
5458
**kwargs: "Any"
5559
) -> None:
5660
super().__init__()
5761
validate_tenant_id(tenant_id)
5862

59-
if isinstance(client_credential, bytes):
63+
self._assertion = user_assertion
64+
65+
if client_certificate:
66+
if client_secret:
67+
raise ValueError('Specifying both "client_certificate" and "client_secret" is not valid.')
6068
try:
61-
cert = get_client_credential(None, kwargs.pop("password", None), client_credential)
69+
cert = get_client_credential(None, kwargs.pop("password", None), client_certificate)
6270
except ValueError as ex:
6371
message = (
64-
'"client_credential" should be either a client secret (a string)'
65-
+ " or the bytes of a certificate in PEM or PKCS12 format"
72+
'"client_certificate" is not a valid certificate in PEM or PKCS12 format'
6673
)
6774
raise ValueError(message) from ex
6875
self._client_credential = AadClientCertificate(
6976
cert["private_key"], password=cert.get("passphrase")
7077
) # type: Union[str, AadClientCertificate]
78+
elif client_secret:
79+
self._client_credential = client_secret
7180
else:
72-
self._client_credential = client_credential
81+
raise TypeError('Either "client_certificate" or "client_secret" must be provided')
7382

7483
# note AadClient handles "authority" and any pipeline kwargs
7584
self._client = AadClient(tenant_id, client_id, **kwargs)
76-
self._assertion = user_assertion
7785

7886
async def __aenter__(self):
7987
await self._client.__aenter__()

sdk/identity/azure-identity/dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
aiohttp>=3.0; python_version >= '3.5'
33
mock;python_version<"3.3"
44
typing_extensions>=3.7.2
5+
cryptography<=3.4.8
56
-e ../../../tools/azure-sdk-tools
67
-e ../../../tools/azure-devtools

0 commit comments

Comments
 (0)