Skip to content

Commit b551e02

Browse files
xiangyan99pvaneckscbedd
authored
Add pop token support (#37482)
* Add pop token support * Update sdk/identity/azure-identity-broker/CHANGELOG.md Co-authored-by: Paul Van Eck <[email protected]> * rename sample * update changelog * Update sdk/identity/azure-identity-broker/CHANGELOG.md Co-authored-by: Paul Van Eck <[email protected]> * unblock this PR. fix incoming in 37450 * Update version Signed-off-by: Paul Van Eck <[email protected]> --------- Signed-off-by: Paul Van Eck <[email protected]> Co-authored-by: Paul Van Eck <[email protected]> Co-authored-by: Scott Beddall <[email protected]>
1 parent 22c2d80 commit b551e02

File tree

7 files changed

+50
-12
lines changed

7 files changed

+50
-12
lines changed

sdk/identity/azure-identity-broker/CHANGELOG.md

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

3-
## 1.1.1 (Unreleased)
3+
## 1.2.0b1 (2024-09-20)
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- `InteractiveBrowserBrokerCredential` now implements the `SupportsTokenInfo` protocol. It now has a `get_token_info` method which returns an `AccessTokenInfo` object. The `get_token_info` method is an alternative method to `get_token` that improves support for more complex authentication scenarios.
8+
- Added Proof-of-Possession (PoP) token support to `InteractiveBrowserBrokerCredential`.
129

1310
## 1.1.0 (2024-04-09)
1411

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5-
from ._browser import InteractiveBrowserBrokerCredential
5+
from ._browser import InteractiveBrowserBrokerCredential, PopTokenRequestOptions
66

77

88
__all__ = [
99
"InteractiveBrowserBrokerCredential",
10+
"PopTokenRequestOptions",
1011
]

sdk/identity/azure-identity-broker/azure/identity/broker/_browser.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
# Licensed under the MIT License.
44
# ------------------------------------
55
import socket
6-
from typing import Dict, Any
6+
from typing import Dict, Any, Mapping, Union
77
import msal
88

99
from azure.core.exceptions import ClientAuthenticationError
10+
from azure.core.credentials import TokenRequestOptions
1011
from azure.identity._credentials import (
1112
InteractiveBrowserCredential as _InteractiveBrowserCredential,
1213
) # pylint:disable=protected-access
@@ -15,6 +16,12 @@
1516
from ._utils import wrap_exceptions, resolve_tenant
1617

1718

19+
class PopTokenRequestOptions(TokenRequestOptions):
20+
"""Options to use for pop token requests."""
21+
22+
pop: Union[bool, Mapping[str, str]]
23+
24+
1825
class InteractiveBrowserBrokerCredential(_InteractiveBrowserCredential):
1926
"""Uses an authentication broker to interactively sign in a user.
2027
@@ -64,8 +71,14 @@ def __init__(self, **kwargs: Any) -> None:
6471
def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
6572
scopes = list(scopes) # type: ignore
6673
claims = kwargs.get("claims")
74+
pop = kwargs.get("pop")
6775
app = self._get_app(**kwargs)
6876
port = self._parsed_url.port if self._parsed_url else None
77+
auth_scheme = None
78+
if pop:
79+
auth_scheme = msal.PopAuthScheme(
80+
http_method=pop["resource_request_method"], url=pop["resource_request_url"], nonce=pop["nonce"]
81+
)
6982

7083
if self._use_default_broker_account:
7184
try:
@@ -78,6 +91,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
7891
port=port,
7992
parent_window_handle=self._parent_window_handle,
8093
enable_msa_passthrough=self._enable_msa_passthrough,
94+
auth_scheme=auth_scheme,
8195
)
8296
if "access_token" in result:
8397
return result
@@ -93,6 +107,7 @@ def _request_token(self, *scopes: str, **kwargs: Any) -> Dict:
93107
port=port,
94108
parent_window_handle=self._parent_window_handle,
95109
enable_msa_passthrough=self._enable_msa_passthrough,
110+
auth_scheme=auth_scheme,
96111
)
97112
except socket.error as ex:
98113
raise CredentialUnavailableError(message="Couldn't start an HTTP server.") from ex

sdk/identity/azure-identity-broker/azure/identity/broker/_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.0b1"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[tool.azure-sdk-build]
22
type_check_samples = false
33
pyright = false
4+
mindependency = false
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
"""
6+
This sample is intended to show how to get a Proof-of-Possession (PoP) token.
7+
"""
8+
9+
from azure.identity.broker import PopTokenRequestOptions, InteractiveBrowserBrokerCredential
10+
11+
nonce = "nonce" # needs to be a valid nonce
12+
resource_request_url = "url" # needs to be a valid URL
13+
resource_request_method = "GET" # needs to be a valid HTTP method
14+
request_options = PopTokenRequestOptions(
15+
{
16+
"pop": {
17+
"nonce": nonce,
18+
"resource_request_url": resource_request_url,
19+
"resource_request_method": resource_request_method,
20+
}
21+
}
22+
)
23+
cred = InteractiveBrowserBrokerCredential(parent_window_handle="window_handle")
24+
pop_token = cred.get_token_info("scope", options=request_options)

sdk/identity/azure-identity-broker/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity-broker",
4242
keywords="azure, azure sdk",
4343
classifiers=[
44-
"Development Status :: 5 - Production/Stable",
44+
"Development Status :: 4 - Beta",
4545
"Programming Language :: Python",
4646
"Programming Language :: Python :: 3 :: Only",
4747
"Programming Language :: Python :: 3",
@@ -62,7 +62,7 @@
6262
},
6363
python_requires=">=3.8",
6464
install_requires=[
65-
"azure-identity<2.0.0,>=1.15.0",
66-
"msal[broker]>=1.25,<2",
65+
"azure-identity<2.0.0,>=1.18.0",
66+
"msal[broker]>=1.31,<2",
6767
],
6868
)

0 commit comments

Comments
 (0)