#! /usr/bin/env python3 # # duo_library.py - simple DUO Python library client template # # Version 1.0, latest version, documentation and bugtracker available at: # https://gitlab.lindenaar.net/scripts/duo # # Copyright (c) 2019 Frederik Lindenaar # # This script is free software: you can redistribute and/or modify it under the # terms of version 3 of the GNU General Public License as published by the Free # Software Foundation, or (at your option) any later version of the license. # # This script is distributed in the hope that it will be useful but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program. If not, visit <http://www.gnu.org/licenses/> to download it. # """ simple DUO Python library client template. This python script uses the DUO API library for python to perform some simple requests to test it and as template to implement a simple client using this library. The logic implemented in this file matches that of the pure Python3 implementation of the API client in duo_api.py to compare them and decide how best to integrate with DUO in your environment. To run this example: 1. create a virtualenv in this directory with: virtualenv . 2. activate the virtualenv with: . ./bin/activate 3. install the required libraries with: pip install -r requirements.txt 4. update this script and provide your API host, ikey and skey below 5. run this script See https://duo.com/docs/authapi and https://duo.com/docs/adminapi for the available endpoints, parameters and responses. For the Python library and its documentation see: https://github.com/duosecurity/duo_client_python """ import duo_client as DUO # Main logic to execute is case this is the called script if __name__ == '__main__': # Instantiate DUO Auth API class, make sure you set parameters below! host='api-XXXXXXXX.duosecurity.com' ikey='XXXXXXXXXXXXXXXXXXXX' skey='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' duo_auth_api = DUO.Auth(host=host, ikey=ikey, skey=skey) # Simple example, check the connectivity response = duo_auth_api.check() print(response) # More complex example, request DUO token authorization with parameters response = duo_auth_api.auth( username='username', factor='push', device='auto', type='Network Access', display_username='Test User', pushinfo='explanation=Text+section(s)+shown+to+the+user&mode=TEST') print(response)