github.com/vmware/go-vcloud-director/v2@v2.24.0/scripts/get_token.sh (about)

     1  #!/usr/bin/env bash
     2  # This script will connect to the vCD using username and password,
     3  # and show the headers that contain a bearer or authorization token.
     4  #
     5  user=$1
     6  password=$2
     7  org=$3
     8  IP=$4
     9  api_version=$5
    10  
    11  if [ -z "$IP" ]
    12  then
    13      echo "Syntax $0 user password organization hostname_or_IP_address [API version]"
    14      exit 1
    15  fi
    16  
    17  auth=$(echo -n "$user@$org:$password" |base64)
    18  
    19  [ -z "$api_version" ] && api_version=32
    20  operation=api/sessions
    21  
    22  # if the requested version is greater than 32 (VCD 10.0+), we can use cloudapi
    23  if [[ $api_version -ge 33  ]]
    24  then
    25      # endpoint for system administrator
    26      operation=cloudapi/1.0.0/sessions/provider
    27      if [ "$org" != "System" -a "$org" != "system" ]
    28      then
    29          # endpoint for org users
    30          operation=cloudapi/1.0.0/sessions
    31      fi
    32  fi
    33  
    34  set -x
    35  curl -I -k --header "Accept: application/*;version=${api_version}.0" \
    36      --header "Authorization: Basic $auth" \
    37      --request POST https://$IP/$operation
    38  
    39  # If successful, the output of this command will include lines like the following
    40  # X-VCLOUD-AUTHORIZATION: 08a321735de84f1d9ec80c3b3e18fa8b
    41  # X-VMWARE-VCLOUD-ACCESS-TOKEN: eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbmlzdHJhdG9yI[562 more characters]
    42  #
    43  # The string after `X-VCLOUD-AUTHORIZATION:` is the old (deprecated) token.
    44  # The 612-character string after `X-VMWARE-VCLOUD-ACCESS-TOKEN` is the bearer token
    45  #
    46  # Note that using cloudapi we will only get the bearer token