Skip to content

Instantly share code, notes, and snippets.

@buckett
Last active March 19, 2019 08:40
Show Gist options
  • Select an option

  • Save buckett/ed3217fced4b9d129758157b4476aaa6 to your computer and use it in GitHub Desktop.

Select an option

Save buckett/ed3217fced4b9d129758157b4476aaa6 to your computer and use it in GitHub Desktop.

Revisions

  1. buckett revised this gist Mar 19, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ccurl
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Just pulls OAuth token for Canvas from keychain and puts it in the Authorization header

    # You can set passwords with:
    # security add-generic-password -a buckett -s canvas.instructure.com -w token_value_here
    # security add-generic-password -a buckett -s canvas.instructure.com -w ....
    # and if you need to update a token you need to first delete it with:
    # security delete-generic-password -a buckett -s canvas.instructure.com
    # This will also mean that the the security tool has read access by default.
    @@ -13,10 +13,10 @@
    canvas_hosts=(${CCURL_HOSTS})
    # If your canvas account isn't your unix username set it with:
    # export CCURL_USER=myusername
    account= ${CCURL_USER:-${USER}}
    account=${CCURL_USER:-${USER}}

    if [ -z "$canvas_hosts" ]; then
    echo "You need to set the CCURL_HOSTS environmental variable to the hosts your want to add authorisation for.""
    echo "You need to set the CCURL_HOSTS environmental variable to the hosts your want to add authorisation for."
    exit 2
    fi

  2. buckett revised this gist Mar 19, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ccurl
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Just pulls OAuth token for Canvas from keychain and puts it in the Authorization header

    # You can set passwords with:
    # security add-generic-password -a buckett -s canvas.instructure.com -w ....
    # security add-generic-password -a buckett -s canvas.instructure.com -w token_value_here
    # and if you need to update a token you need to first delete it with:
    # security delete-generic-password -a buckett -s canvas.instructure.com
    # This will also mean that the the security tool has read access by default.
  3. buckett created this gist Mar 19, 2019.
    41 changes: 41 additions & 0 deletions ccurl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/bin/bash
    # Canvas cURL
    # Just pulls OAuth token for Canvas from keychain and puts it in the Authorization header

    # You can set passwords with:
    # security add-generic-password -a buckett -s canvas.instructure.com -w ....
    # and if you need to update a token you need to first delete it with:
    # security delete-generic-password -a buckett -s canvas.instructure.com
    # This will also mean that the the security tool has read access by default.

    # This should be set with something like:
    # export CCURL_HOSTS="inst.instructure.com inst.test.instructure.com inst.beta.instructure.com"
    canvas_hosts=(${CCURL_HOSTS})
    # If your canvas account isn't your unix username set it with:
    # export CCURL_USER=myusername
    account= ${CCURL_USER:-${USER}}

    if [ -z "$canvas_hosts" ]; then
    echo "You need to set the CCURL_HOSTS environmental variable to the hosts your want to add authorisation for.""
    exit 2
    fi
    for host in ${canvas_hosts[@]}; do
    if [[ $@ == *${host}* ]]; then
    service=$host
    break
    fi
    done
    if [ -z "$service" ]; then
    echo "Failed to find service in arguments." 1>&2
    exit 2
    fi
    token=$(security find-generic-password -s ${service} -a ${account} -w 2>/dev/null)
    if [ -z "$token" ]; then
    echo "Failed to find token, looking for account $account for $service" 1>&2
    exit 3
    fi
    exec curl -H "Authorization: Bearer ${token}" "$@"