Skip to main content

An implementation of the Duo Security API authentication scheme.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

duo_hmac-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

duo_hmac-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file duo_hmac-0.1.0.tar.gz.

File metadata

  • Download URL: duo_hmac-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for duo_hmac-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e3f7a87e76cd6ddf1df7ce0f50b33911d699f8036c7910e943a533bd1ccccd71
MD5 806e0a8d074949aa4f0f023b157c0ffe
BLAKE2b-256 f46eaf00ade1b130c7d0a1bf9baa7c8f998300f669d4753ca3d483abd6f3f593

See more details on using hashes here.

File details

Details for the file duo_hmac-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: duo_hmac-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for duo_hmac-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05e7d20af5f484a3235339363f6cbb912ae5edb7b274b0b40846f874ce0ba9a3
MD5 3b579b75fbd3f8376c5347fceaf30664
BLAKE2b-256 1a0373e676fe7f0368fbbfe762e5877644ffc2d3f4454038d5c43d5d7f40bdd2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page