The following sample code demonstrates authentication with VSP One Object. It shows the full login process (via Keycloak) and, in the final section, how to obtain the XSRF and Vert.x web session tokens (via /csrf) and apply them when calling a MAPI endpoint.
# =============================================
# Input parameters:
GALAXY_FQDN=$1 # e.g. "galaxy9.vsp1o.example.com"
REGION=$2 # e.g. "boston"
USERNAME=$3
USERPASS=$4
MAPI_ENDPOINT=${5:-"user/info"}
# Internal parameters:
CLIENT_ID="vsp-object-external-client"
REALM="vsp-object"
MAPI_URL="https://admin.${REGION}.${GALAXY_FQDN}/mapi/v1"
KEYCLOAK_URL="https://admin.gms.${GALAXY_FQDN}/ui/auth"
# Get access token:
OUTPUT=$(curl -k -d "grant_type=password" \
-d "username=$USERNAME" \
-d "password=$USERPASS" \
-d "client_id=$CLIENT_ID" \
"${KEYCLOAK_URL}/realms/${REALM}/protocol/openid-connect/token" --insecure 2> /dev/null)
ACCESS_TOKEN=$(echo "$OUTPUT" | jq -r '.access_token' 2> /dev/null)
# Get cookies (XSRF + session):
cookieResponse=$(curl -skc - ${MAPI_URL}/csrf 2> /dev/null)
xsrf=$(echo "$cookieResponse" | grep XSRF-TOKEN | awk -F"XSRF-TOKEN" '{ print $2 }' | tr -d " \t")
vertx=$(echo "$cookieResponse" | grep vertx-web.session | awk -F"vertx-web.session" '{ print $2 }' | tr -d " \t")
# Call MAPI endpoint:
curl -k -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "X-XSRF-TOKEN: $xsrf" \
-b "XSRF-TOKEN=$xsrf; vertx-web.session=$vertx;" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
"${MAPI_URL}/${MAPI_ENDPOINT}" \
-X POST
# =============================================
Version: 1.1.0