Skip to content

Commit 347c625

Browse files
authored
[Identity] Stop using deprecated datetime methods (#36952)
Signed-off-by: Paul Van Eck <[email protected]>
1 parent 50f0fa2 commit 347c625

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5-
from datetime import datetime
5+
from datetime import datetime, timezone
66
import time
77
from typing import Dict, Optional, Callable, Any
88

@@ -93,10 +93,9 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
9393
raise ClientAuthenticationError(
9494
message="Couldn't begin authentication: {}".format(flow.get("error_description") or flow.get("error"))
9595
)
96-
9796
if self._prompt_callback:
9897
self._prompt_callback(
99-
flow["verification_uri"], flow["user_code"], datetime.utcfromtimestamp(flow["expires_at"])
98+
flow["verification_uri"], flow["user_code"], datetime.fromtimestamp(flow["expires_at"], timezone.utc)
10099
)
101100
else:
102101
print(flow["message"])

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_device_code_credential():
209209
disable_instance_discovery=True,
210210
)
211211

212-
now = datetime.datetime.utcnow()
212+
now = datetime.datetime.now(datetime.timezone.utc)
213213
token = credential.get_token("scope")
214214
assert token.token == expected_token
215215

@@ -269,7 +269,6 @@ def test_tenant_id():
269269
additionally_allowed_tenants=["*"],
270270
)
271271

272-
now = datetime.datetime.utcnow()
273272
token = credential.get_token("scope", tenant_id="tenant_id")
274273
assert token.token == expected_token
275274

0 commit comments

Comments
 (0)