Duo Security Python Client

repository·master·Indexed 41 days ago

https://github.com/duosecurity/duo_client_python

Official Python client for interacting with Duo Security APIs, including Authentication (Auth), Administration (Admin), and Activity endpoints. It provides programmatic access to manage users, groups, devices, policies, and audit logs, as well as tools for integrating MFA into third-party applications. Supports Python versions 3.7 through 3.12.

Tokens
3K
Snippets
14
Records
22
Agent score
100%

What's inside Duo Security Python Client

  1. Overview of the Duo Admin API module

    master

    The Admin module in duo_client_python is designed to automate the management of account-level elements within a Duo customer configuration. It provides programmatic access to manage the following resources:

    • Users: Manage user accounts and attributes.
    • Groups: Manage user groups.
    • Phones/Tablets: Manage registered devices.
    • Tokens: Manage authentication tokens.
    • Application integrations: Manage Duo application settings.
    • Policies: Manage security policies.
    • Logs: Access and manage audit logs.
  2. Duo Python Client requirements and compatibility

    master

    Python Versions

    Supported versions: 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.

    TLS Support

    The client uses Python's ssl module and OpenSSL. Python 3.7 and higher provide support for both TLS 1.2 and TLS 1.3.

  3. Manage subaccounts using the Admin module

    master

    Subaccount management (intended for Managed Service Partners to automate child account management) should be performed using the Admin module.

    Important Deprecation Notice: While the Accounts client provides subaccount methods like get_child_accounts, create_account, and delete_account, these are deprecated and will be removed in a future release. Their functionality is frozen. For all new code, use the Admin module instead.

    # Use Admin for subaccount management
    # Avoid the deprecated Accounts client for these methods
    # Methods include: get_child_accounts, create_account, delete_account
  4. Understand the Duo Auth API usage model

    master

    The Duo Auth API is designed for integrating user enrollment and authentication into custom third-party applications.

    Key Integration Pattern:

    1. The third-party application provides the user interface.
    2. The application performs primary authentication for the user.
    3. The application calls the Duo Auth API to initiate secure second-factor authentication (MFA).

    Note that the examples provided in this repository use console/tty-based interactions to simulate the data collection required for functional interactions with the Duo Auth API.

  5. Use the Duo Admin API for account operations

    master

    The Duo Admin API is used for operational tasks related to Duo account management. Use these examples if you need to automate tasks such as:

    • User management: Creating, updating, or deleting users.
    • MFA device management: Managing user authentication devices.
    • Integration management: Managing Duo integrations.
    • Policy management: Configuring Duo security policies.
    • Log extractions: Retrieving logs from Duo.
    • Subaccount management: Managing subaccounts (primarily for Duo Managed Service Provider (MSP) partners). For subaccount examples, refer to the Accounts folder.
  6. Install duo-client for development

    master

    If you are contributing to the repository, clone the repo, set up a virtual environment, and install the requirements for both the library and development tools.

    $ git clone https://github.com/duosecurity/duo_client_python.git
    $ cd duo_client_python
    $ virtualenv .env
    $ source .env/bin/activate
    $ pip install --requirement requirements.txt
    $ pip install --requirement requirements-dev.txt
    $ python setup.py install
  7. Run subaccount management examples

    master

    To run the provided subaccount management examples, execute the Python scripts from the repository root or from within the specific example directory.

    # From the repo root
    python3 examples/Accounts/get_billing_and_telephony_credits.py
    
    # Or from within the examples/Accounts/ folder
    python3 get_billing_and_telephony_credits.py
  8. Run Duo Admin API examples

    master

    To run the provided Admin API examples, execute the Python scripts from either the repository root or from within the examples/Admin/ directory. For example, to run the report_users_and_phones.py script:

    # From the repo root
    python3 examples/Admin/report_users_and_phones.py
    
    # Or, from within the examples/Admin/ folder
    python3 report_users_and_phones.py