Skip to content

Commit a37d3a3

Browse files
authored
Pass Sku and Ver to MsalRuntime (#786)
* Pass Sku and Ver to MsalRuntime * edit suggestions * suggestion edits * whitespace
1 parent 3f3d133 commit a37d3a3

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

msal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
#------------------------------------------------------------------------------
2727

2828
from .application import (
29-
__version__,
3029
ClientApplication,
3130
ConfidentialClientApplication,
3231
PublicClientApplication,
3332
)
3433
from .oauth2cli.oidc import Prompt, IdTokenError
34+
from .sku import __version__
3535
from .token_cache import TokenCache, SerializableTokenCache
3636
from .auth_scheme import PopAuthScheme
3737
from .managed_identity import (

msal/application.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
from .region import _detect_region
2020
from .throttled_http_client import ThrottledHttpClient
2121
from .cloudshell import _is_running_in_cloud_shell
22+
from .sku import SKU, __version__
2223

2324

24-
# The __init__.py will import this. Not the other way around.
25-
__version__ = "1.31.1" # When releasing, also check and bump our dependencies's versions if needed
2625

2726
logger = logging.getLogger(__name__)
2827
_AUTHORITY_TYPE_CLOUDSHELL = "CLOUDSHELL"
@@ -770,7 +769,7 @@ def _build_client(self, client_credential, authority, skip_regional_client=False
770769
client_assertion = None
771770
client_assertion_type = None
772771
default_headers = {
773-
"x-client-sku": "MSAL.Python", "x-client-ver": __version__,
772+
"x-client-sku": SKU, "x-client-ver": __version__,
774773
"x-client-os": sys.platform,
775774
"x-ms-lib-capability": "retry-after, h429",
776775
}

msal/broker.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import uuid
99

10+
from .sku import __version__, SKU
1011

1112
logger = logging.getLogger(__name__)
1213
try:
@@ -135,13 +136,18 @@ def _get_new_correlation_id():
135136
def _enable_msa_pt(params):
136137
params.set_additional_parameter("msal_request_type", "consumer_passthrough") # PyMsalRuntime 0.8+
137138

139+
def _build_msal_runtime_auth_params(client_id, authority):
140+
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
141+
params.set_additional_parameter("msal_client_sku", SKU)
142+
params.set_additional_parameter("msal_client_ver", __version__)
143+
return params
138144

139145
def _signin_silently(
140146
authority, client_id, scopes, correlation_id=None, claims=None,
141147
enable_msa_pt=False,
142148
auth_scheme=None,
143149
**kwargs):
144-
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
150+
params = _build_msal_runtime_auth_params(client_id, authority)
145151
params.set_requested_scopes(scopes)
146152
if claims:
147153
params.set_decoded_claims(claims)
@@ -174,7 +180,7 @@ def _signin_interactively(
174180
enable_msa_pt=False,
175181
auth_scheme=None,
176182
**kwargs):
177-
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
183+
params = _build_msal_runtime_auth_params(client_id, authority)
178184
params.set_requested_scopes(scopes)
179185
params.set_redirect_uri(
180186
_redirect_uri_on_mac if sys.platform == "darwin" else
@@ -230,7 +236,7 @@ def _acquire_token_silently(
230236
account = _read_account_by_id(account_id, correlation_id)
231237
if account is None:
232238
return
233-
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
239+
params = _build_msal_runtime_auth_params(client_id, authority)
234240
params.set_requested_scopes(scopes)
235241
if claims:
236242
params.set_decoded_claims(claims)

msal/sku.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""This module is from where we recieve the client sku name and version.
2+
"""
3+
4+
# The __init__.py will import this. Not the other way around.
5+
__version__ = "1.31.1" # When releasing, also check and bump our dependencies's versions if needed
6+
SKU = "MSAL.Python"

0 commit comments

Comments
 (0)