Skip to content

Commit 77a5b9d

Browse files
authored
Adding app_name and app_version headers (#136)
1 parent c578d36 commit 77a5b9d

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

msal/application.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
client_credential=None, authority=None, validate_authority=True,
7474
token_cache=None,
7575
verify=True, proxies=None, timeout=None,
76-
client_claims=None):
76+
client_claims=None, app_name=None, app_version=None):
7777
"""Create an instance of application.
7878
7979
:param client_id: Your app has a client_id after you register it on AAD.
@@ -131,13 +131,21 @@ def __init__(
131131
It will be passed to the
132132
`timeout parameter in the underlying requests library
133133
<http://docs.python-requests.org/en/v2.9.1/user/advanced/#timeouts>`_
134+
:param app_name: (optional)
135+
You can provide your application name for Microsoft telemetry purposes.
136+
Default value is None, means it will not be passed to Microsoft.
137+
:param app_version: (optional)
138+
You can provide your application version for Microsoft telemetry purposes.
139+
Default value is None, means it will not be passed to Microsoft.
134140
"""
135141
self.client_id = client_id
136142
self.client_credential = client_credential
137143
self.client_claims = client_claims
138144
self.verify = verify
139145
self.proxies = proxies
140146
self.timeout = timeout
147+
self.app_name = app_name
148+
self.app_version = app_version
141149
self.authority = Authority(
142150
authority or "https://login.microsoftonline.com/common/",
143151
validate_authority, verify=verify, proxies=proxies, timeout=timeout)
@@ -149,6 +157,15 @@ def __init__(
149157
def _build_client(self, client_credential, authority):
150158
client_assertion = None
151159
client_assertion_type = None
160+
default_headers = {
161+
"x-client-sku": "MSAL.Python", "x-client-ver": __version__,
162+
"x-client-os": sys.platform,
163+
"x-client-cpu": "x64" if sys.maxsize > 2 ** 32 else "x86",
164+
}
165+
if self.app_name:
166+
default_headers['x-app-name'] = self.app_name
167+
if self.app_version:
168+
default_headers['x-app-ver'] = self.app_version
152169
default_body = {"client_info": 1}
153170
if isinstance(client_credential, dict):
154171
assert ("private_key" in client_credential
@@ -174,11 +191,7 @@ def _build_client(self, client_credential, authority):
174191
return Client(
175192
server_configuration,
176193
self.client_id,
177-
default_headers={
178-
"x-client-sku": "MSAL.Python", "x-client-ver": __version__,
179-
"x-client-os": sys.platform,
180-
"x-client-cpu": "x64" if sys.maxsize > 2 ** 32 else "x86",
181-
},
194+
default_headers=default_headers,
182195
default_body=default_body,
183196
client_assertion=client_assertion,
184197
client_assertion_type=client_assertion_type,

0 commit comments

Comments
 (0)