Skip to main content

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

Metadata

Release files for duo-hmac 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for duo-hmac 0.1.0
File Size Uploaded
duo_hmac-0.1.0.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for duo-hmac 0.1.0
File Interpreter ABI Platform
duo_hmac-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.9 kB

Release files / duo_hmac-0.1.0.tar.gz

Download URL duo_hmac-0.1.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e3f7a87e76cd6ddf1df7ce0f50b33911d699f8036c7910e943a533bd1ccccd71
BLAKE2b-256 checksum
How to use checksums
f46eaf00ade1b130c7d0a1bf9baa7c8f998300f669d4753ca3d483abd6f3f593
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / duo_hmac-0.1.0-py3-none-any.whl

Download URL duo_hmac-0.1.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05e7d20af5f484a3235339363f6cbb912ae5edb7b274b0b40846f874ce0ba9a3
BLAKE2b-256 checksum
How to use checksums
1a0373e676fe7f0368fbbfe762e5877644ffc2d3f4454038d5c43d5d7f40bdd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page