class InteractiveLoginTokenProvider(TokenProviderBase): """Acquire a token from MSAL with Device Login flow""" def __init__(self, kusto_uri: str, authority_uri: str, login_hint: Optional[str] = None, domain_hint: Optional[str] = None): super().__init__(kusto_uri) self._msal_client = None self._auth = authority_uri self._login_hint = login_hint self._domain_hint = domain_hint self._account = None @staticmethod def name() -> str: return "InteractiveLoginTokenProvider" def context(self) -> dict: return {"authority": self._auth, "client_id": self._cloud_info.kusto_client_app_id} def _init_impl(self): self._msal_client = PublicClientApplication(client_id=self._cloud_info.kusto_client_app_id, authority=self._auth) def _get_token_impl(self) -> dict: token = self._msal_client.acquire_token_interactive( scopes=self._scopes, prompt=TokenConstants.MSAL_INTERACTIVE_PROMPT, login_hint=self._login_hint, domain_hint=self._domain_hint ) return self._valid_token_or_throw(token) def _get_token_from_cache_impl(self) -> dict: account = None accounts = self._msal_client.get_accounts(self._login_hint) if len(accounts) > 0: account = accounts[0] token = self._msal_client.acquire_token_silent(scopes=self._scopes, account=account) return self._valid_token_or_none(token)
def Authorize(self): bSDD_ClientID = '4aba821f-d4ff-498b-a462-c2837dbbba70' bSDD_Scope = "https://buildingsmartservices.onmicrosoft.com/api/read" from msal import PublicClientApplication bSDD_authority = 'https://buildingsmartservices.b2clogin.com/tfp/buildingsmartservices.onmicrosoft.com/b2c_1_signupsignin' app = PublicClientApplication( bSDD_ClientID, authority=bSDD_authority ) #need localhost redirection on azure portal for the client ID flow = app.initiate_auth_code_flow(scopes=[bSDD_Scope]) self.Token = app.acquire_token_interactive(scopes=[bSDD_Scope]) print('logged in')