def authentication(mode):
    """
    Authenticates a username against a stored password, if any, otherwise
    requires a password is to be entered.

    :Args:
        - cfg (:class:`.Configuration`): an instance of class Configuration as
          returned by create_config()

    :Returns:
        - a :class:`.Credentials` instance object
    """

    try:
        return AzureOAuth.get_unattended_session(config=mode)

    except (AuthenticationException, InvalidConfigException) as e:
        print("Could not get unattended session: {0}".format(e))

    try:
        auth_url = AzureOAuth.get_authorization_url(config=mode)[0]
        webbrowser.open(auth_url)
        redirect_url = input("Please enter authentication url: ")
        return AzureOAuth.get_authorization_token(redirect_url, config=mode)

    except (AuthenticationException, InvalidConfigException) as e:
        print("Failed to get authorization: {0}".format(e))
def authentication(cfg):
    """
    Attempts to retrieve an existing session otherwise creates a new session.

    :Returns:
        - An instance of the :class:`batchapps.Credentials`.
    """

    try:
        return AzureOAuth.get_unattended_session(config=cfg)

    except (AuthenticationException, InvalidConfigException) as exp:
        print("Unable to authenticate via Unattended Acocunt: {0}".format(exp))

    try:
        return AzureOAuth.get_session(config=cfg)

    except AuthenticationException as exp:
        print("Could not get existing session: {0}".format(exp))

    except InvalidConfigException as exp:
        raise RuntimeError("Failed to authenticate. {0}".format(exp))

    try:
        webbrowser.open(AzureOAuth.get_authorization_url(config=cfg)[0])
        auth_url = input("Please enter authentication url: ")

        return AzureOAuth.get_authorization_token(auth_url, config=AzureOAuth.config)

    except (AuthenticationException, InvalidConfigException) as exp:
        raise RuntimeError("Failed to get authorization: {0}".format(exp))
def authentication(mode):
    """
    Authenticates a username against a stored password, if any, otherwise
    requires a password is to be entered.

    :Args:
        - cfg (:class:`.Configuration`): an instance of class Configuration as
          returned by create_config()

    :Returns:
        - a :class:`.Credentials` instance object
    """

    try:
        return AzureOAuth.get_unattended_session(config=mode)

    except (AuthenticationException, InvalidConfigException) as e:
        print("Could not get unattended session: {0}".format(e))
        
    try:
        auth_url = AzureOAuth.get_authorization_url(config=mode)[0]
        webbrowser.open(auth_url)
        redirect_url = input("Please enter authentication url: ")
        return AzureOAuth.get_authorization_token(redirect_url,
                                                  config=mode)

    except (AuthenticationException, InvalidConfigException) as e:
        print("Failed to get authorization: {0}".format(e))
def authentication(cfg):
    """
    Attempts to retrieve an existing session otherwise creates a new session.

    :Returns:
        - An instance of the :class:`batchapps.Credentials`.
    """

    try:
        return AzureOAuth.get_unattended_session(config=cfg)

    except (AuthenticationException, InvalidConfigException) as exp:
        print("Unable to authenticate via Unattended Acocunt: {0}".format(exp))

    try:
        return AzureOAuth.get_session(config=cfg)

    except AuthenticationException as exp:
        print("Could not get existing session: {0}".format(exp))

    except InvalidConfigException as exp:
        raise RuntimeError("Failed to authenticate. {0}".format(exp))

    try:
        webbrowser.open(AzureOAuth.get_authorization_url(config=cfg)[0])
        auth_url = input("Please enter authentication url: ")

        return AzureOAuth.get_authorization_token(auth_url,
                                                  config=AzureOAuth.config)

    except (AuthenticationException, InvalidConfigException) as exp:
        raise RuntimeError("Failed to get authorization: {0}".format(exp))