msticpy/common/azure_auth_core.py
def az_connect_core(
    auth_methods: List[str] = None, silent: bool = False
) -> AzCredentials:
    """
    Authenticate using multiple authentication sources.

    Parameters
    ----------
    auth_methods
        List of authentication methods to try
        Possible options are:
        - "env" - to get authentication details from environment varibales
        - "cli" - to use Azure CLI authentication details
        - "msi" - to user Managed Service Indenity details
        - "interactive" - to prompt for interactive login
        Default is ["env", "cli", "msi", "interactive"]

    silent
        Whether to display any output during auth process. Default is False.

    Returns
    -------
    AzCredentials
        Named tuple of:
        - legacy (ADAL) credentials
        - modern (MSAL) credentials

    Raises
    ------
    CloudError
        If chained token credential creation fails.
    MsticpyAzureConnectionError
        If invalid auth options are presented.

    Notes
    -----
    The function tries to obtain credentials from the following
    sources:
    - Azure Auth Environment variables
    - Azure CLI (if an active session is logged on)
    - Managed Service Identity
    - Interactive browser logon
    If the authentication is successful both ADAL (legacy) and
    MSAL (modern) credential types are returned.

    """
    if not auth_methods:
        auth_methods = default_auth_methods()
    try:
        auths = [_AUTH_OPTIONS[meth] for meth in auth_methods]
    except KeyError as err:
        raise MsticpyAzureConnectionError(
            "Unknown authentication option, valid options are; env, cli, msi, interactive"
        ) from err

    # Filter and replace error message when credentials not found
    handler = logging.StreamHandler(sys.stdout)
    if silent:
        handler.addFilter(_filter_all_warnings)
    else:
        handler.addFilter(_filter_credential_warning)
    logging.basicConfig(level=logging.WARNING, handlers=[handler])

    # Create credentials and connect to the subscription client to validate
    creds = ChainedTokenCredential(*auths)  # type: ignore
    legacy_creds = CredentialWrapper(creds)
    if not creds:
        raise CloudError("Could not obtain credentials.")

    return AzCredentials(legacy_creds, creds)

    Authenticate using multiple authentication sources.

    Parameters
    ----------
    auth_methods
        List of authentication methods to try
        Possible options are:
        - "env" - to get authentication details from environment varibales
        - "cli" - to use Azure CLI authentication details
        - "msi" - to user Managed Service Indenity details
        - "interactive" - to prompt for interactive login
        Default is ["env", "cli", "msi", "interactive"]

    silent
        Whether to display any output during auth process. Default is False.

    Returns
    -------
    AzCredentials
        Named tuple of:
        - legacy (ADAL) credentials
        - modern (MSAL) credentials

    Raises
    ------
    CloudError
        If chained token credential creation fails.
    MsticpyAzureConnectionError
        If invalid auth options are presented.

    Notes
    -----
    The function tries to obtain credentials from the following
    sources:
    - Azure Auth Environment variables
    - Azure CLI (if an active session is logged on)
    - Managed Service Identity
    - Interactive browser logon
    If the authentication is successful both ADAL (legacy) and
    MSAL (modern) credential types are returned.

    
Authenticate using multiple authentication sources.
Parameters



silent
Whether to display any output during auth process. Default is False.

Returns

AzCredentials
Named tuple of:
legacy (ADAL) credentials
modern (MSAL) credentials

Raises

CloudError
If chained token credential creation fails.
MsticpyAzureConnectionError
If invalid auth options are presented.

Notes

The function tries to obtain credentials from the following
sources:
Azure Auth Environment variables
Azure CLI (if an active session is logged on)
Managed Service Identity
Interactive browser logon
If the authentication is successful both ADAL (legacy) and
MSAL (modern) credential types are returned.
Authenticate using multiple authentication sources . Parameters silent Whether to display any output during auth process . Default is False . Returns AzCredentials Named tuple of : legacy ( ADAL ) credentials modern ( MSAL ) credentials Raises CloudError If chained token credential creation fails . MsticpyAzureConnectionError If invalid auth options are presented . Notes The function tries to obtain credentials from the following sources : Azure Auth Environment variables Azure CLI ( if an active session is logged on ) Managed Service Identity Interactive browser logon If the authentication is successful both ADAL ( legacy ) and MSAL ( modern ) credential types are returned .
def az_connect_core(
    auth_methods: List[str] = None, silent: bool = False
) -> AzCredentials:
    if not auth_methods:
        auth_methods = default_auth_methods()
    try:
        auths = [_AUTH_OPTIONS[meth] for meth in auth_methods]
    except KeyError as err:
        raise MsticpyAzureConnectionError(
            "Unknown authentication option, valid options are; env, cli, msi, interactive"
        ) from err
    handler = logging.StreamHandler(sys.stdout)
    if silent:
        handler.addFilter(_filter_all_warnings)
    else:
        handler.addFilter(_filter_credential_warning)
    logging.basicConfig(level=logging.WARNING, handlers=[handler])
    creds = ChainedTokenCredential(*auths)  
    legacy_creds = CredentialWrapper(creds)
    if not creds:
        raise CloudError("Could not obtain credentials.")
    return AzCredentials(legacy_creds, creds)
def az_connect_core ( auth_methods : List [ str ] = None , silent : bool = False ) -> AzCredentials : if not auth_methods : auth_methods = default_auth_methods ( ) try : auths = [ _AUTH_OPTIONS [ meth ] for meth in auth_methods ] except KeyError as err : raise MsticpyAzureConnectionError ( "Unknown authentication option, valid options are; env, cli, msi, interactive" ) from err handler = logging . StreamHandler ( sys . stdout ) if silent : handler . addFilter ( _filter_all_warnings ) else : handler . addFilter ( _filter_credential_warning ) logging . basicConfig ( level = logging . WARNING , handlers = [ handler ] ) creds = ChainedTokenCredential ( * auths ) legacy_creds = CredentialWrapper ( creds ) if not creds : raise CloudError ( "Could not obtain credentials." ) return AzCredentials ( legacy_creds , creds )
Authenticate using multiple authentication sources.
Authenticate using multiple authentication sources .
"""
    Authenticate using multiple authentication sources.

    Parameters
    ----------
    auth_methods
        List of authentication methods to try
        Possible options are:
        - "env" - to get authentication details from environment varibales
        - "cli" - to use Azure CLI authentication details
        - "msi" - to user Managed Service Indenity details
        - "interactive" - to prompt for interactive login
        Default is ["env", "cli", "msi", "interactive"]

    silent
        Whether to display any output during auth process. Default is False.

    Returns
    -------
    AzCredentials
        Named tuple of:
        - legacy (ADAL) credentials
        - modern (MSAL) credentials

    Raises
    ------
    CloudError
        If chained token credential creation fails.
    MsticpyAzureConnectionError
        If invalid auth options are presented.

    Notes
    -----
    The function tries to obtain credentials from the following
    sources:
    - Azure Auth Environment variables
    - Azure CLI (if an active session is logged on)
    - Managed Service Identity
    - Interactive browser logon
    If the authentication is successful both ADAL (legacy) and
    MSAL (modern) credential types are returned.

    """ # Filter and replace error message when credentials not found # Create credentials and connect to the subscription client to validate # type: ignore
auth_methods
List[str]
silent
bool