Skip to content

Commit af1bf48

Browse files
authored
[Python] pass auth flows into credential policy (#3062)
* Update dependencies (2025-03-26 05:20:22) * Regenerate for typespec-python (2025-03-26 05:24:34) * Update dependencies (2025-03-27 06:37:28) * Regenerate for typespec-python (2025-03-27 06:41:52) * Update dependencies (2025-03-31 05:41:59) * udpate --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent 6a27094 commit af1bf48

16 files changed

Lines changed: 175 additions & 15 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: feature
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Pass authentication flows info into credential policy for unbranded

packages/autorest.python/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "~0.8.3-dev.1",
32+
"@typespec/http-client-python": "~0.8.3-dev.2",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"

packages/typespec-python/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"@typespec/rest": ">=0.67.0 <1.0.0",
5151
"@typespec/versioning": ">=0.67.0 <1.0.0",
5252
"@typespec/openapi": ">=0.67.0 <1.0.0",
53+
"@typespec/events": ">=0.67.0 <1.0.0",
54+
"@typespec/sse": ">=0.67.0 <1.0.0",
55+
"@typespec/streams": ">=0.67.0 <1.0.0",
5356
"@azure-tools/typespec-azure-core": ">=0.53.0 <1.0.0",
5457
"@azure-tools/typespec-azure-resource-manager": ">=0.53.0 <1.0.0",
5558
"@azure-tools/typespec-autorest": ">=0.53.0 <1.0.0",
@@ -60,7 +63,7 @@
6063
"js-yaml": "~4.1.0",
6164
"semver": "~7.6.2",
6265
"tsx": "~4.19.1",
63-
"@typespec/http-client-python": "~0.8.3-dev.1",
66+
"@typespec/http-client-python": "~0.8.3-dev.2",
6467
"fs-extra": "~11.2.0"
6568
},
6669
"devDependencies": {
@@ -69,6 +72,9 @@
6972
"@typespec/rest": "~0.67.0",
7073
"@typespec/versioning": "~0.67.0",
7174
"@typespec/openapi": "~0.67.0",
75+
"@typespec/events": "~0.67.0",
76+
"@typespec/sse": "~0.67.0",
77+
"@typespec/streams": "~0.67.0",
7278
"@azure-tools/typespec-azure-resource-manager": "~0.53.0",
7379
"@azure-tools/typespec-azure-core": "~0.53.0",
7480
"@azure-tools/typespec-azure-rulesets": "~0.53.0",

packages/typespec-python/test/azure/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ azure-mgmt-core==1.3.2
4646
-e ./generated/server-versions-versioned
4747
-e ./generated/server-versions-not-versioned
4848
-e ./generated/special-words
49+
-e ./generated/streaming-jsonl
4950
-e ./generated/typetest-array
5051
-e ./generated/typetest-dictionary
5152
-e ./generated/typetest-enum-extensible

packages/typespec-python/test/generic_mock_api_tests/asynctests/test_authentication_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class FakeCredential:
3333
async def get_token(*scopes):
3434
return core_library.credentials.AccessToken(token="".join(scopes), expires_on=1800)
3535

36+
@staticmethod
37+
async def get_token_info(*scopes, **kwargs):
38+
return core_library.credentials.AccessTokenInfo(token="".join(scopes), expires_on=1800)
39+
3640
return FakeCredential()
3741

3842

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
import pytest
7+
8+
from streaming.jsonl.aio import JsonlClient
9+
10+
11+
@pytest.fixture
12+
async def client():
13+
async with JsonlClient(endpoint="http://localhost:3000") as client:
14+
yield client
15+
16+
17+
JSONL = b'{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}'
18+
19+
20+
@pytest.mark.asyncio
21+
async def test_basic_send(client: JsonlClient):
22+
await client.basic.send(JSONL)
23+
24+
25+
@pytest.mark.asyncio
26+
async def test_basic_recv(client: JsonlClient):
27+
assert b"".join([d async for d in (await client.basic.receive())]) == JSONL

packages/typespec-python/test/generic_mock_api_tests/test_authentication.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class FakeCredential:
3333
def get_token(*scopes):
3434
return core_library.credentials.AccessToken(token="".join(scopes), expires_on=1800)
3535

36+
@staticmethod
37+
def get_token_info(*scopes, **kwargs):
38+
return core_library.credentials.AccessTokenInfo(token="".join(scopes), expires_on=1800)
39+
3640
return FakeCredential()
3741

3842

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
import pytest
7+
8+
from streaming.jsonl import JsonlClient
9+
10+
11+
@pytest.fixture
12+
def client():
13+
with JsonlClient(endpoint="http://localhost:3000") as client:
14+
yield client
15+
16+
17+
JSONL = b'{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}'
18+
19+
20+
def test_basic_send(client: JsonlClient):
21+
client.basic.send(JSONL)
22+
23+
24+
def test_basic_recv(client: JsonlClient):
25+
assert b"".join(client.basic.receive()) == JSONL

packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_configuration.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@ def _configure(self, **kwargs: Any) -> None:
4242
self.authentication_policy = kwargs.get("authentication_policy")
4343
if self.credential and not self.authentication_policy:
4444
self.authentication_policy = policies.BearerTokenCredentialPolicy(
45-
self.credential, *self.credential_scopes, **kwargs
45+
self.credential,
46+
*self.credential_scopes,
47+
auth_flows=[
48+
{
49+
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
50+
"scopes": [{"value": "https://security.microsoft.com/.default"}],
51+
"type": "implicit",
52+
}
53+
],
54+
**kwargs
4655
)

packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/aio/_configuration.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,14 @@ def _configure(self, **kwargs: Any) -> None:
4444
self.authentication_policy = kwargs.get("authentication_policy")
4545
if self.credential and not self.authentication_policy:
4646
self.authentication_policy = policies.AsyncBearerTokenCredentialPolicy(
47-
self.credential, *self.credential_scopes, **kwargs
47+
self.credential,
48+
*self.credential_scopes,
49+
auth_flows=[
50+
{
51+
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
52+
"scopes": [{"value": "https://security.microsoft.com/.default"}],
53+
"type": "implicit",
54+
}
55+
],
56+
**kwargs
4857
)

0 commit comments

Comments
 (0)