Skip to content

Pass Sku and Ver to MsalRuntime #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion msal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#------------------------------------------------------------------------------

from .application import (
__version__,
ClientApplication,
ConfidentialClientApplication,
PublicClientApplication,
)
from .oauth2cli.oidc import Prompt, IdTokenError
from .sku import __version__
from .token_cache import TokenCache, SerializableTokenCache
from .auth_scheme import PopAuthScheme
from .managed_identity import (
Expand Down
5 changes: 2 additions & 3 deletions msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from .region import _detect_region
from .throttled_http_client import ThrottledHttpClient
from .cloudshell import _is_running_in_cloud_shell
from .sku import SKU, __version__


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

logger = logging.getLogger(__name__)
_AUTHORITY_TYPE_CLOUDSHELL = "CLOUDSHELL"
Expand Down Expand Up @@ -770,7 +769,7 @@ def _build_client(self, client_credential, authority, skip_regional_client=False
client_assertion = None
client_assertion_type = None
default_headers = {
"x-client-sku": "MSAL.Python", "x-client-ver": __version__,
"x-client-sku": SKU, "x-client-ver": __version__,
"x-client-os": sys.platform,
"x-ms-lib-capability": "retry-after, h429",
}
Expand Down
12 changes: 9 additions & 3 deletions msal/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import uuid

from .sku import __version__, SKU

logger = logging.getLogger(__name__)
try:
Expand Down Expand Up @@ -135,13 +136,18 @@ def _get_new_correlation_id():
def _enable_msa_pt(params):
params.set_additional_parameter("msal_request_type", "consumer_passthrough") # PyMsalRuntime 0.8+

def _build_msal_runtime_auth_params(client_id, authority):
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
params.set_additional_parameter("msal_client_sku", SKU)
params.set_additional_parameter("msal_client_ver", __version__)
return params

def _signin_silently(
authority, client_id, scopes, correlation_id=None, claims=None,
enable_msa_pt=False,
auth_scheme=None,
**kwargs):
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
params = _build_msal_runtime_auth_params(client_id, authority)
params.set_requested_scopes(scopes)
if claims:
params.set_decoded_claims(claims)
Expand Down Expand Up @@ -174,7 +180,7 @@ def _signin_interactively(
enable_msa_pt=False,
auth_scheme=None,
**kwargs):
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
params = _build_msal_runtime_auth_params(client_id, authority)
params.set_requested_scopes(scopes)
params.set_redirect_uri(
_redirect_uri_on_mac if sys.platform == "darwin" else
Expand Down Expand Up @@ -230,7 +236,7 @@ def _acquire_token_silently(
account = _read_account_by_id(account_id, correlation_id)
if account is None:
return
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
params = _build_msal_runtime_auth_params(client_id, authority)
params.set_requested_scopes(scopes)
if claims:
params.set_decoded_claims(claims)
Expand Down
6 changes: 6 additions & 0 deletions msal/sku.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""This module is from where we recieve the client sku name and version.
"""

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