5.185 Authenticate Against the Viewpoint Template API

The Viewpoint Template API requires users to authenticate to it using cookies.

This topic provides an example on how to authenticate using cURL to get a valid cookie that can be used to validate your access.

Do the following:

  1. Create the following script:
    #!/bin/bash
     
    REQUEST_METHOD=$1
    REQUEST_URL=$2
     
    LOGIN_URL=http://localhost:8080/login/
    YOUR_USER='moab-admin'
    YOUR_PASS='changeme!'
    COOKIES=cookies.txt
    CURL_BIN="curl -s -c $COOKIES -b $COOKIES -e $LOGIN_URL"
    echo "Django Auth: get csrftoken ..."
    $CURL_BIN $LOGIN_URL > /dev/null
    DJANGO_TOKEN="csrfmiddlewaretoken=$(grep cid $COOKIES | sed 's/^.*cid\s*//')"
    echo "DJANGO TOKEN is $DJANGO_TOKEN"
    echo "######################################################"
    echo "Performing login..."
    $CURL_BIN \
        -d "$DJANGO_TOKEN&uName=$YOUR_USER&pwd=$YOUR_PASS" \
        -X POST $LOGIN_URL
    echo "######################################################"
    echo "Request: $REQUEST_METHOD $REQUEST_URL"
    $CURL_BIN \
        -d "$DJANGO_TOKEN&..." \
        -X $REQUEST_METHOD \
        -H "Accept:Application/json" \
        $REQUEST_URL \
        | python -m json.tool
    rm $COOKIES
  2. Consume the API by running this script:
    ./iris-curl.sh GET "http://localhost:8080/api/templates/"

Related Topics 

© 2016 Adaptive Computing