def __init__(self, username=None, **kwargs):  # pylint:disable=unused-argument
        # type: (Optional[str], **Any) -> None

        self._authority = kwargs.pop(
            "authority", None) or KnownAuthorities.AZURE_PUBLIC_CLOUD
        self._authority_aliases = KNOWN_ALIASES.get(
            self._authority) or frozenset((self._authority, ))
        self._username = username
        self._tenant_id = kwargs.pop("tenant_id", None)

        cache = kwargs.pop("_cache", None)  # for ease of testing

        if not cache and sys.platform.startswith(
                "win") and "LOCALAPPDATA" in os.environ:
            from msal_extensions.token_cache import WindowsTokenCache

            cache = WindowsTokenCache(cache_location=os.path.join(
                os.environ["LOCALAPPDATA"], ".IdentityService", "msal.cache"))

            # prevent writing to the shared cache
            # TODO: seperating deserializing access tokens from caching them would make this cleaner
            cache.add = lambda *_, **__: None

        if cache:
            self._cache = cache
            self._client = self._get_auth_client(
                authority=self._authority, cache=cache,
                **kwargs)  # type: Optional[AadClientBase]
        else:
            self._client = None
Ejemplo n.º 2
0
    def __init__(self, username, **kwargs):  # pylint:disable=unused-argument
        # type: (str, **Any) -> None

        self._username = username

        cache = None

        if sys.platform.startswith("win") and "LOCALAPPDATA" in os.environ:
            from msal_extensions.token_cache import WindowsTokenCache

            cache = WindowsTokenCache(cache_location=os.environ["LOCALAPPDATA"] + "/.IdentityService/msal.cache")

            # prevent writing to the shared cache
            # TODO: seperating deserializing access tokens from caching them would make this cleaner
            cache.add = lambda *_: None

        if cache:
            self._client = self._get_auth_client(cache)  # type: Optional[AuthnClientBase]
        else:
            self._client = None