Skip to content
Merged
Changes from 2 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
15 changes: 12 additions & 3 deletions msal/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import time
import uuid

from .application import __version__

@rayluo rayluo Feb 6, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better add a new sku.py which contains nothing but SKU="..." and __version__ = "...", and then we have both application.py and broker.py (plus __init__.py) do from .sku import .... This way, the application.py and broker.py will not have a circular reference to each other.



logger = logging.getLogger(__name__)


try:
import pymsalruntime # Its API description is available in site-packages/pymsalruntime/PyMsalRuntime.pyi
pymsalruntime.register_logging_callback(lambda message, level: { # New in pymsalruntime 0.7
Expand Down Expand Up @@ -135,13 +139,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", "MSAL.Python")
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 +183,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 +239,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