Skip to content

Commit c89dc2b

Browse files
authored
Update azure-identity history and version (#9437)
1 parent 772e3a5 commit c89dc2b

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

sdk/identity/azure-identity/HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 1.1.1 (Unreleased)
3+
## 1.2.0 (2020-01-14)
44

55
- All credential pipelines include `ProxyPolicy`
66
([#8945](https://github.com/Azure/azure-sdk-for-python/pull/8945))

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.1.1"
5+
VERSION = "1.2.0"

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import TYPE_CHECKING
77

88
from azure.core.exceptions import ClientAuthenticationError
9+
from .base import AsyncCredentialBase
910
from .._internal import AadClient
1011

1112
if TYPE_CHECKING:
@@ -14,7 +15,7 @@
1415
from azure.core.credentials import AccessToken
1516

1617

17-
class AuthorizationCodeCredential(object):
18+
class AuthorizationCodeCredential(AsyncCredentialBase):
1819
"""Authenticates by redeeming an authorization code previously obtained from Azure Active Directory.
1920
2021
See https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow for more information
@@ -31,13 +32,19 @@ class AuthorizationCodeCredential(object):
3132
:keyword str client_secret: One of the application's client secrets. Required only for web apps and web APIs.
3233
"""
3334

35+
async def __aenter__(self):
36+
if self._client:
37+
await self._client.__aenter__()
38+
return self
39+
40+
async def close(self):
41+
"""Close the credential's transport session."""
42+
43+
if self._client:
44+
await self._client.__aexit__()
45+
3446
def __init__(
35-
self,
36-
tenant_id: str,
37-
client_id: str,
38-
authorization_code: str,
39-
redirect_uri: str,
40-
**kwargs: "Any"
47+
self, tenant_id: str, client_id: str, authorization_code: str, redirect_uri: str, **kwargs: "Any"
4148
) -> None:
4249
self._authorization_code = authorization_code # type: Optional[str]
4350
self._client_id = client_id

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import pytest
1414

1515
from helpers import build_aad_response, mock_response, Request
16-
from helpers_async import async_validating_transport, wrap_in_future
16+
from helpers_async import async_validating_transport, AsyncMockTransport, wrap_in_future
1717

1818

1919
@pytest.mark.asyncio
@@ -32,6 +32,32 @@ async def send(*_, **__):
3232
assert policy.on_request.called
3333

3434

35+
@pytest.mark.asyncio
36+
async def test_close():
37+
transport = AsyncMockTransport()
38+
credential = AuthorizationCodeCredential(
39+
"tenant-id", "client-id", "auth-code", "http://localhost", transport=transport
40+
)
41+
42+
await credential.close()
43+
44+
assert transport.__aexit__.call_count == 1
45+
46+
47+
@pytest.mark.asyncio
48+
async def test_context_manager():
49+
transport = AsyncMockTransport()
50+
credential = AuthorizationCodeCredential(
51+
"tenant-id", "client-id", "auth-code", "http://localhost", transport=transport
52+
)
53+
54+
async with credential:
55+
assert transport.__aenter__.call_count == 1
56+
57+
assert transport.__aenter__.call_count == 1
58+
assert transport.__aexit__.call_count == 1
59+
60+
3561
@pytest.mark.asyncio
3662
async def test_user_agent():
3763
transport = async_validating_transport(

0 commit comments

Comments
 (0)