Prepare Execution Environment#

1.1 Create shell script#

An access token is required for API authentication and execution. To obtain the access token, first create a shell script called "get_token.sh”.
There are 2 options for the user authentication method;
(1) Password Authentication,
(2) Certificate + Password Authentication
When you choose the ‘(2) Certificate + Password Authentication’, some additional contents to the shell script and preparation for the client certificate are required.

In this section, the following explanations are based on '(1) Password Authentication '. To indicate the additional contents for ‘(2) Certificate + Password Authentication’, the corresponding parts are tabbed.

get_token.sh

#!/bin/bash
# FJCS account information
CONTRACT_NUMBER=<FJCS Contract number>
USER_NAME=<FJCS User name>
USER_PW=<FJCS Password>
# URI
TOKEN=https://auth-api.jp-east-1.paas.cloud.global.fujitsu.com/API/paas/auth/token
# Temporary file to store token value
TMPFILE=./token.txt

echo ""
echo "****************************************"
echo "** Get Token			    **"
echo "****************************************"
echo ""
echo "Settings:"
echo " endpoint:$TOKEN"
echo " contract_number:$CONTRACT_NUMBER"
echo " user_name:$USER_NAME"
echo " user_pw:$USER_PW"
echo ""
echo "CURL command to be executed:"
echo "curl -si -X POST  $TOKEN -H \"Content-Type:application/json\" -d '{ \"auth\":{ \"identity\":{ \"password\":{ \"user\":{\"contract_number\":\"$CONTRACT_NUMBER\", \"name\":\"$USER_NAME\", \"password\":\"$USER_PW\" } } } } }' "
curl -si -X POST  $TOKEN -H "Content-Type:application/json" -d '{ "auth":{ "identity":{ "password":{ "user":{"contract_number":"'$CONTRACT_NUMBER'", "name":"'$USER_NAME'", "password":"'$USER_PW'" } } } } }' | awk '/X-Access-Token/ {print $2}' > $TMPFILE | tr -d '\r\n'

OS_AUTH_TOKEN=`cat $TMPFILE | tr -d '\r\n'`
echo "=== Token value from here ==="
echo $OS_AUTH_TOKEN
echo "=== Token value to here   ==="
#!/bin/bash
# FJCS account information
CONTRACT_NUMBER=<FJCS Contract number>
USER_NAME=<FJCS User name>
USER_PW=<FJCS Password>
# URI
TOKEN=https://auth-api.jp-east-1.paas.cloud.global.fujitsu.com/API/paas/auth/token
# Temporary file to store token value
TMPFILE=./token.txt

echo ""
echo "****************************************"
echo "** Get Token			    **"
echo "****************************************"
echo ""
echo "Settings:"
echo " endpoint:$TOKEN"
echo " contract_number:$CONTRACT_NUMBER"
echo " user_name:$USER_NAME"
echo " user_pw:$USER_PW"
echo ""
echo "CURL command to be executed:"
echo "curl -si -X POST  $TOKEN -H "X-FCX-Client-Cert: Client certificate mapped to the user account" -H \"Content-Type:application/json\" -d '{ \"auth\":{ \"identity\":{ \"password\":{ \"user\":{\"contract_number\":\"$CONTRACT_NUMBER\", \"name\":\"$USER_NAME\", \"password\":\"$USER_PW\" } } } } }' "
curl -si -X POST  $TOKEN -H "X-FCX-Client-Cert: Client certificate mapped to the user account" -H "Content-Type:application/json" -d '{ "auth":{ "identity":{ "password":{ "user":{"contract_number":"'$CONTRACT_NUMBER'", "name":"'$USER_NAME'", "password":"'$USER_PW'" } } } } }' | awk '/X-Access-Token/ {print $2}' > $TMPFILE | tr -d '\r\n'

OS_AUTH_TOKEN=`cat $TMPFILE | tr -d '\r\n'`
echo "=== Token value from here ==="
echo $OS_AUTH_TOKEN
echo "=== Token value to here   ==="

# Preparation for (2) Certificate + Password Authentication
# Get the client certificate ready With appropriate commands, convert the client certificate file to a PEM file using openssl. 
# The alpha-numeral string enclosed between "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" in the file is the "Client certificate mapped to the user account".

1.2 Get token#

This section explains how to obtain the access token using the"get_token.sh" shell script created in Section 1.1.

  1. Change to working directory.

    $ cd <Directory in which get_token.sh exists>
    

  2. Execute shell script

    $ ./get_token.sh
    

The following result will be displayed on the console:

****************************************
** Get Token			      **
****************************************

Settings:
 endpoint: https://auth-api.jp-east-1.paas.cloud.global.fujitsu.com/API/paas/auth/token
 contract_number: <FJCS Contract number>
 user_name: <FJCS User name>
 user_pw: <FJCS Password>

CURL command to be executed:
curl -si -X POST  https://auth-api.jp-east-1.paas.cloud.global.fujitsu.com/API/paas/auth/token -H "Content-Type:application/json" -d '{ "auth":{ "identity":{ "password":{ "user":{"contract_number":"<FJCS Contract number>", "name":" <FJCS User name> ", "password":"<FJCS Password>" } } } } }'

=== Token value from here ===
<Token value>
=== Token value to here   ===
****************************************
** Get Token			      **
****************************************

Settings:
 endpoint: https://auth-api.jp-east-1.paas.cloud.global.fujitsu.com/API/paas/auth/token
 contract_number: <FJCS Contract number>
 user_name: <FJCS User name>
 user_pw: <FJCS Password>

CURL command to be executed:
curl -si -X POST  https://auth-api.jp-east-1.paas.cloud.global.fujitsu.com/API/paas/auth/token -H "X-FCX-Client-Cert: Client certificate mapped to the user account" -H "Content-Type:application/json" -d '{ "auth":{ "identity":{ "password":{ "user":{"contract_number":"<FJCS Contract number>", "name":" <FJCS User name> ", "password":"<FJCS Password>" } } } } }'

=== Token value from here ===
<Token value>
=== Token value to here   ===

The Token acquired above will be used for API authentication. Hereafter, when executing API, please use the Token obtained with the described steps.

Set the Token value to API header and send a request. For more details, please refer to execution examples in Chapter3.