Authorization
To generate the authorization token to access Veridata REST APIs, copy the below script to a script file on the linux box and edit the following parameters:
- USERNAME="<username>"
This is the Veridata user created.
- PASSWORD="<password>"
This is the password of Veridata user.
- URL="http://<host>:<port>/veridata/v1/auth/login"
Host: Veridata
Server hostname port: Veridata Server port
-
Save and run the script, to generate the Veridata authorization token.
#!/bin/bash # Function to generate MD5 hash md5_hash() { echo -n "$1" | openssl dgst -md5 | awk '{print $2}' } # Variables USERNAME="<userName>" PASSWORD="<password>" REALM="" NONCE="" QOP="" CNONCE=$(openssl rand -hex 8) # Random client nonce OPAQUE="" ALGORITHM="MD5" URL="http://<host>:<port>/veridata/v1/auth/login" API_URL="/v1/auth/login" # First call to get digest details (WWW-Authenticate header) response_headers=$(curl -s -I "$URL" | grep -i 'WWW-Authenticate-Custom') # Extracting the necessary fields from the WWW-Authenticate header REALM=$(echo "$response_headers" | grep -Eo 'realm="([^"]*)"' | cut -d'"' -f2) NONCE=$(echo "$response_headers" | grep -Eo 'nonce="([^"]*)"' | cut -d'"' -f2) QOP=$(echo "$response_headers" | grep -Eo 'qop="([^"]*)"' | cut -d'"' -f2) OPAQUE=$(echo "$response_headers" | grep -Eo 'opaque="([^"]*)"' | cut -d'"' -f2) # Generate HA1, HA2, and response based on Digest Authentication process HA1=$(md5_hash "$USERNAME:$REALM:$PASSWORD") HA2=$(md5_hash "GET:$API_URL") NC="00000001" # Nonce count RESPONSE=$(md5_hash "$HA1:$NONCE:$NC:$CNONCE:$QOP:$HA2") # Generate Authorization header AUTH_HEADER="Digest username=\"$USERNAME\", realm=\"$REALM\", nonce=\"$NONCE\", uri=\"$API_URL\", algorithm=$ALGORITHM, qop=$QOP, nc=$NC, cnonce=\"$CNONCE\", opaque=\"$OPAQUE\", response=\"$RESPONSE\"" # Perform second call with Authorization header curl -v -H "Authorization: $AUTH_HEADER" "$URL"