<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: API Help with Bash Script in APIs</title>
    <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878196#M184</link>
    <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;It did not work for me.ANyone had any shell script that worked for the Duo Admin API&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 07 Jan 2022 23:15:54 GMT</pubDate>
    <dc:creator>Sushmita_Saha</dc:creator>
    <dc:date>2022-01-07T23:15:54Z</dc:date>
    <item>
      <title>API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878191#M179</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;Howdy All,&lt;/P&gt;
&lt;P&gt;First let me admit my ignorance with APIs, and assume that I know nothing.&lt;/P&gt;
&lt;P&gt;#!/bin/bash -u&lt;/P&gt;
&lt;P&gt;FORM=“Content-Type: application/x-www-form-urlencoded”&lt;BR /&gt;
NOW=$(date -R)&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="hashtag"&gt;#get&lt;/SPAN&gt; these from the Duo Admin interface&lt;BR /&gt;
INT=“obfuscated integration key from admin page”&lt;BR /&gt;
KEY=“obfuscated secret key from admin page”&lt;BR /&gt;
API=“&lt;A href="http://api-nnn.duosecurity.com" rel="noopener nofollow ugc"&gt;■■■■■■■■■■■■■■■■■■■■■■■&lt;/A&gt;”&lt;/P&gt;
&lt;P&gt;URL="/auth/v2/check"&lt;BR /&gt;
#URL="/admin/v1/users"&lt;BR /&gt;
REQ="$NOW\nGET\n$API\n$URL\n"&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="hashtag"&gt;#could&lt;/SPAN&gt; also use awk here, or the --binary mode as suggested elsewhere&lt;BR /&gt;
HMAC=$(echo -n “$REQ” | openssl sha1 -hmac “$KEY” | cut -d" " -f 2)&lt;/P&gt;
&lt;P&gt;AUTH=$(echo -n “$INT:$HMAC” | base64 -w0)&lt;/P&gt;
&lt;P&gt;curl -s -H “Date: $NOW” -H $FORM -H “Authorization: Basic $AUTH” &lt;A&gt;https://$API$URL&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;gives me this error:&lt;BR /&gt;
{“code”: 40301, “message”: “Access forbidden”, “message_detail”: “Wrong integration type for this API.”, “stat”: “FAIL”}&lt;/P&gt;
&lt;P&gt;If i change it to the “admin” url i get this error&lt;BR /&gt;
{“code”: 40103, “message”: “Invalid signature in request credentials”, “stat”: “FAIL”}&lt;/P&gt;
&lt;P&gt;Basically i want to pull a user l list via the API, but i can’t even get past the authentication piece.&lt;/P&gt;
&lt;P&gt;Any help here is much appreciated.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 09 Jun 2021 17:41:08 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878191#M179</guid>
      <dc:creator>Ben_Holmes</dc:creator>
      <dc:date>2021-06-09T17:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878192#M180</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I cannot vouch for the code, but you have to use the integration keys for Auth API application in the Duo console when using the auth/vs/check. it sound like you might have just the admin API defined.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 Aug 2021 17:15:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878192#M180</guid>
      <dc:creator>jonblac</dc:creator>
      <dc:date>2021-08-09T17:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878193#M181</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;Adding our Rep Taylor so she can see.&lt;/P&gt;
&lt;P&gt;I have both the Admin and the Auth API keys.&lt;/P&gt;
&lt;P&gt;Just need some help on making the HMAC SH1 string and then basic authentication.&lt;/P&gt;
&lt;P&gt;i.e. It would be nice to this broken into more steps&lt;/P&gt;
&lt;P&gt;&lt;A href="https://mandrillapp.com/track/click/30344824/duo.com?p=eyJzIjoiVC1IblJrSklrbkxEQWtTUnotc0ZzYzM4aHpNIiwidiI6MSwicCI6IntcInVcIjozMDM0NDgyNCxcInZcIjoxLFwidXJsXCI6XCJodHRwczpcXFwvXFxcL2R1by5jb21cXFwvZG9jc1xcXC9hdXRoYXBpI2FwaS1kZXRhaWxzXCIsXCJpZFwiOlwiOTRlZGE0ODE1ZDFkNDNhMWEzMDEzMTc2NGEwMWJhOThcIixcInVybF9pZHNcIjpbXCI1ZDA3ZjdkODEwOTMyNGI5ODg4ZDA2ZGM1MDI1OWZjZWY4MmY0ZTg4XCJdfSJ9" rel="noopener nofollow ugc"&gt;https://duo.com/docs/authapi#api-details&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 Aug 2021 18:30:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878193#M181</guid>
      <dc:creator>Ben_Holmes</dc:creator>
      <dc:date>2021-08-09T18:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878194#M182</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;Have you found the answer to this?   I am getting the same thing and have followed the documentation.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 19 Sep 2021 01:36:09 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878194#M182</guid>
      <dc:creator>HenryEgal</dc:creator>
      <dc:date>2021-09-19T01:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878195#M183</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;Maybe try not concatenating the request with that newline character?&lt;/P&gt;
&lt;P&gt;Like instead of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;REQ="$NOW\nGET\n$API\n$URL\n"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;REQ="$NOW
GET
$API
$URL
"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I try what you have posted here I get actual &lt;CODE&gt;\n&lt;/CODE&gt; in the request (I am on a Mac though right now).&lt;/P&gt;
&lt;P&gt;ETA: I saw a &lt;A href="https://stackoverflow.com/questions/18535902/concatenating-two-string-variables-in-bash-appending-newline"&gt;StackOverflow post tagged with Linux and bash&lt;/A&gt; where someone noted that &lt;CODE&gt;\n&lt;/CODE&gt; was inserting whitespace, which would also throw off the signature.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 20 Sep 2021 15:46:42 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878195#M183</guid>
      <dc:creator>DuoKristina</dc:creator>
      <dc:date>2021-09-20T15:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878196#M184</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;It did not work for me.ANyone had any shell script that worked for the Duo Admin API&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Jan 2022 23:15:54 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878196#M184</guid>
      <dc:creator>Sushmita_Saha</dc:creator>
      <dc:date>2022-01-07T23:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878197#M185</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;I haven’t got it working with Bash either. But I did have someone get it working in Python, but I can’t use that.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 08 Jan 2022 00:04:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878197#M185</guid>
      <dc:creator>Ben_Holmes</dc:creator>
      <dc:date>2022-01-08T00:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878198#M186</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;The support shown for this kind of stuff here is…&lt;/P&gt;
&lt;P&gt;They provide some simple PoC code based on unit tests and from there on, you’re on your own. No functional-ready-to-copy-paste code that you can use.&lt;/P&gt;
&lt;P&gt;I managed to build a wrapper shell script against the nodejs module they provide, so I have, so far (I’m just adding commands as we need them):&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;DIV class="lightbox-wrapper"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="2X_4_4465cd443e7ef2de4f11d9c565651fbd35e449c5.jpeg" style="width: 690px;"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/190705i306CAD07C19AEC42/image-size/large?v=v2&amp;amp;px=999" role="button" title="2X_4_4465cd443e7ef2de4f11d9c565651fbd35e449c5.jpeg" alt="2X_4_4465cd443e7ef2de4f11d9c565651fbd35e449c5.jpeg" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Anyway it should be easy (I think) too for python wrapping a shell script against this basic command structure:&lt;/P&gt;
&lt;P&gt;python -m duo_client.client --ikey nnn --skey nnn --host nnn --path /admin/blah/blah limit=200 --method GET/POST/DELETE&lt;/P&gt;
&lt;P&gt;(I don’t know how you specify the parameters there sorry, maybe just in the way the “limit” is specified above).&lt;/P&gt;
&lt;P&gt;Regards.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 11 Jan 2022 15:13:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878198#M186</guid>
      <dc:creator>Ruben_Cardenal</dc:creator>
      <dc:date>2022-01-11T15:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878199#M187</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;I know this is a fairly old thread, but it was the hint I needed to figure out how to use bash to successfully make requests via curl so here goes.&lt;/P&gt;
&lt;P&gt;Personal note: I didn’t have much luck with the var=$(command) notation for executing and capturing output to variables. So I used var=`command` notation instead. May be my system or that I am just dense and missing something so take that with a grain of sand.&lt;/P&gt;
&lt;P&gt;So here is what I had to change to get this working from a bash script&lt;BR /&gt;
1&amp;gt; You are not including a blank line in your request where parameters would go if you had any.&lt;BR /&gt;
2&amp;gt; I used the ${var} notation to make sure that bash didn’t have any ambiguity issues when building strings from variables&lt;BR /&gt;
3&amp;gt; Lastly you didn’t need to base64 encode the auth string, using --basic with -u ikey:hmac curl will take care of the encoding&lt;/P&gt;
&lt;P&gt;So here is my example bash code to talk to the admin api&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;#!/usr/bin/bash
type='Content-Type: application/x-www-form-urlencoded'
now=`/usr/bin/date -R`
method="GET"
ikey='####################'
skey='########################################'
host='■■■■■■■■■■■■■■■■■■■■■■■■■■■■'
path='/admin/v1/users'
params=''
req="${now}
${method}
${host}
${path}
${params}"
hmac=`/usr/bin/echo -n "${req}" | /usr/bin/openssl sha1 -hmac ${skey} | /usr/bin/cut -d" " -f 2`

/usr/bin/curl -s -H "Date: ${now}" -H "${type}" -u "${ikey}:${hmac}" --basic https://${host}${path}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 13 Sep 2022 04:07:14 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878199#M187</guid>
      <dc:creator>Trey1</dc:creator>
      <dc:date>2022-09-13T04:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: API Help with Bash Script</title>
      <link>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878200#M188</link>
      <description>&lt;DIV class="duo-migrated-content"&gt;&lt;P&gt;Just in case anyone is looking for examples of using the api to post updates. Here is the snippet I added to the system setup script I use for building new VMs. It does assume that there is a pam_duo.conf.skel file in the same location as the setup script.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="lang-auto"&gt;## ------------------- DUO MFA ------------------- ##
## use duo api to generate host specific 'app' for use in setting up pam_duo
## gather timestamp and host for header and request body
myhost=`hostname -s`
duonow=`/usr/bin/date -R`
## set content type header and http method
duoctype="Content-Type: application/x-www-form-urlencoded"
duomethod="POST"

## set vars for message signing, authentication, host, and path  obtained from duo
## should really be pulled from a secure repository of some sort
duoikey="####################"
duoskey="########################################"
duohost="■■■■■■■■■■■■■■■■■■■■■■■■■■■■"
duopath="/admin/v1/integrations"

## build params string
duoparams="groups_allowed=####################&amp;amp;name=${myhost}&amp;amp;type=unix&amp;amp;username_normalization_policy=Simple"

## build request for generating hmac sig
duoreq="${duonow}
${duomethod}
${duohost}
${duopath}
${duoparams}"

## generate sig for auth
duohmac=`/usr/bin/echo -n "${duoreq}" | /usr/bin/openssl sha1 -hmac ${duoskey} | /usr/bin/cut -d" " -f 2`

## make call and capture json response
duoresponse=`/usr/bin/curl -s -H "Date: ${duonow}" -H "${duoctype}" -u "${duoikey}:${duohmac}" -X POST --basic https://${duohost}${duopath}?${duoparams}`

## capture new ikey and skey
ikey=`/usr/bin/echo ${duoresponse} | /usr/bin/jq -j '.response.integration_key'`
skey=`/usr/bin/echo ${duoresponse} | /usr/bin/jq -j '.response.secret_key'`

## set up /etc/duo/pam_duo.conf
/usr/bin/cp ./pam_duo.conf.skel /etc/duo/pam_duo.conf
/usr/bin/sed -i "s/.*ikey.*/ikey = ${ikey}/" /etc/duo/pam_duo.conf
/usr/bin/sed -i "s/.*skey.*/skey = ${skey}/" /etc/duo/pam_duo.conf
/usr/bin/sed -i "s/.*host.*/host = ${duohost}/" /etc/duo/pam_duo.conf
/usr/bin/echo -e '/etc/duo/pam_duo.conf configured'
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 15 Sep 2022 18:06:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/apis/api-help-with-bash-script/m-p/4878200#M188</guid>
      <dc:creator>Trey1</dc:creator>
      <dc:date>2022-09-15T18:06:15Z</dc:date>
    </item>
  </channel>
</rss>

