You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

duo-hmac

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duo-hmac

An implementation of the Duo Security API authentication scheme.

0.1.0
pipPyPI
Maintainers
1

Overview

This repository provides an implementation of Duo's current API authentication scheme independent of any HTTP/REST client. If you want a full Python client for the Duo API, see duo_client_python instead.

Currently this supports the Auth API, Admin API, and Accounts API.

It is a pure python library with no third-party runtime dependencies, so it should be suitable in any Python HTTP client you wish to use.

Tested Against Python Versions

  • 3.8
  • 3.9
  • 3.10
  • 3.11

Requirements

Duo_hmac_python requires Python 3.8 or higher.

Installation

Install from PyPi

pip install duo_hmac

Usage

Instantiate a DuoHmac object with your API credentials from the Duo Admin Panel.

from duo_hmac.duo_hmac import DuoHmac

duo = DuoHmac(IKEY, SKEY, API_HOST)

See the Duo API reference documentation for the details of the API calls:

Then provide the API call information according to the documentation for the API call you wish to use:

  • HTTP Method
  • Path of the API call
  • (Optional) API call parameters
  • (Optional) Any additional headers

The values returned are:

  • The uri, query string included, to use for the API call
  • The request body, if any
  • The full set of header values that need to be sent
url, body, headers = duo.get_authentication_components(METHOD, API_PATH, PARAMETERS, HEADERS)

Helper scripts

Two CLI helper scripts are provided in this repository. Provide your Duo API credentials in the duo.conf file to use these scripts.

Check Credentials

This script supports Admin or Auth API credentials.

It will attempt to authenticate against the Duo APIs and report if your credentials were valid. If this script fails, it is likely the credentials are incorrect, or there are problems connecting to Duo.

./check_credentials.py

or

python -m check_credentials

Generate Curl Call

This script supports Admin, Auth, or Accounts API credentials.

This script accepts API call information via CLI flags and outputs a curl command that can make an API request. This is useful for exploring the APIs, or determining the correct authentication header for an API call.

Use the -h flag to see usage instructions

./generate_curl_call.py -h

or

python -m generate_curl_call -h

Development

For this library, Duo accepts GitHub issues as bug reports or for proposed changes. If you want to contribute via a PR, please ensure you include new tests as appropriate, and that the tests all pass. Please also confirm that your code meets the PEP8 style standards. You can run the tests and linter as noted below.

Testing

python -m unittest discover test/

Linting

python -m flake8

Keywords

duo

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts