. ./config.txt

# Print test case detailed output to result_details file
echo "-------------------------------------$testcase:-------------------------------------------------- "  >> $result_details
echo "Validate Access token with tokeninfo and userinfo Endpoint. " >> $result_details
echo "" >> $result_details

#Send Token Request with Scope
curl -v -k -X POST -d 'grant_type=password&client_id='"$client_id"'&client_secret='"$client_secret"'&username='"$username"'&password='"$password"'&scope=email+profile' "$grant_url" -o "curloutput"


#Get Access token
echo -n "access_token value is: "
token_access=`cat curloutput |  jq ".access_token" | grep "\"" | cut -d\" -f2`

echo " Token output is : $token_access " >> $result_details

#Send Access token to Token Info Endpoint
curl -k --header "Authorization: Bearer $token_access" "$verifytoken" -o tokeninfo.txt
echo " TokenInfo Endpoint - token information is :  " >> $result_details
cat "tokeninfo.txt" >> $result_details
echo "" >> $result_details

#Send Access Token to user Info Endpoint
curl -k --header "Authorization: Bearer $token_access" "$userinfo" -o userinfo.txt
echo " UserInfo Endpoint - token information is :  " >> $result_details
cat "userinfo.txt" >> $result_details
echo "" >> $result_details

echo " ----------------------------------------------------------------------------------------------------------------" >>  $result_details

echo -n $testcase":PASSED" >> $result_summary
rm userinfo.txt curloutput tokeninfo.txt

