Example scripts

Note that the scripts expect the OAuth2 client secret to be set as an environment variable:

ex: export CLIENT_SECRET=scimsecret

create_user.sh

#!/bin/sh VERTICAL=$1 TEST_ENV=$2 USERNAME=$3 PHONE_NUMBER=$4 if [ -z $VERTICAL ] || [ -z $TEST_ENV ] || [ -z $CLIENT_SECRET ] || [ -z $USERNAME ]; then echo "ERROR: Invalid parameters:" echo "USAGE: export CLIENT_SECRET=scimsecret" echo "USAGE: $0 <vertical> <test-env> <username> [phonenumber]" if [ -z $VERTICAL ]; then echo "Missing argument <vertical>" fi if [ -z $TEST_ENV ]; then echo "Missing argument <test-env>" fi if [ -z $USERNAME ]; then echo "Missing argument <username>" fi if [ -z $CLIENT_SECRET ]; then echo "Missing environment variable CLIENT_SECRET" fi exit 1 fi echo "-----------------------------------------------------------------------------------------------------------------" echo " VERTICAL $VERTICAL - TEST environment: $TEST_ENV" echo "-----------------------------------------------------------------------------------------------------------------" REALM=$VERTICAL TOKENS_JSON=$( curl -H "Content-Type: application/x-www-form-urlencoded" \ -X POST "https://auth.${VERTICAL}.${TEST_ENV}.buypass.no/auth/realms/${REALM}/protocol/openid-connect/token" \ -d "grant_type=client_credentials&client_id=scim-api-client&client_secret=${CLIENT_SECRET}" 2>/dev/null ) # Get the Access Token (using the jq tool) ACCESS_TOKEN=$(jq -r '.access_token' <<<"${TOKENS_JSON}") if [ -z $PHONE_NUMBER ]; then curl -X POST "https://api.${VERTICAL}.${TEST_ENV}.buypass.no/scim/v2/Users" \ -H "accept: application/scim+json" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ -H "Content-Type: application/scim+json" \ -d "{\"schemas\":[\"urn:ietf:params:scim:schemas:extension:buypass:fido2:User\", \"urn:ietf:params:scim:schemas:core:2.0:User\"], \"userName\":\"${USERNAME}\", \"active\":true}" | jq else curl -X POST "https://api.${VERTICAL}.${TEST_ENV}.buypass.no/scim/v2/Users" \ -H "accept: application/scim+json" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ -H "Content-Type: application/scim+json" \ -d "{\"schemas\":[\"urn:ietf:params:scim:schemas:extension:buypass:fido2:User\", \"urn:ietf:params:scim:schemas:core:2.0:User\"], \"userName\":\"${USERNAME}\", \"active\":true, \"phoneNumbers\":[{\"value\":\"${PHONE_NUMBER}\",\"type\":\"mobile\"}]}" | jq fi echo

get_user.sh

#!/bin/sh VERTICAL=$1 TEST_ENV=$2 USERNAME=$3 if [ -z $VERTICAL ] || [ -z $TEST_ENV ] || [ -z $CLIENT_SECRET ]; then echo "ERROR: Invalid parameters:" echo "USAGE: export CLIENT_SECRET=scimsecret" echo "USAGE: $0 <vertical> <test-env> [username]" if [ -z $VERTICAL ]; then echo "Missing argument <vertical>" fi if [ -z $TEST_ENV ]; then echo "Missing argument <test-env>" fi if [ -z $CLIENT_SECRET ]; then echo "Missing environment variable CLIENT_SECRET" fi exit 1 fi echo "-----------------------------------------------------------------------------------------------------------------" echo " VERTICAL $VERTICAL - TEST environment: $TEST_ENV" echo "-----------------------------------------------------------------------------------------------------------------" REALM=$VERTICAL TOKENS_JSON=$( curl -H "Content-Type: application/x-www-form-urlencoded" \ -X POST "https://auth.${VERTICAL}.${TEST_ENV}.buypass.no/auth/realms/${REALM}/protocol/openid-connect/token" \ -d "grant_type=client_credentials&client_id=scim-api-client&client_secret=${CLIENT_SECRET}" 2>/dev/null ) # Get the Access Token (using the jq tool) ACCESS_TOKEN=$(jq -r '.access_token' <<<"${TOKENS_JSON}") if [ -z $USERNAME ]; then curl -X GET "https://api.${VERTICAL}.${TEST_ENV}.buypass.no/scim/v2/Users" \ -H "accept: application/scim+json" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" | jq else URLENCODED_FILTER="userName%20eq%20%22${USERNAME}%22" curl -X GET "https://api.${VERTICAL}.${TEST_ENV}.buypass.no/scim/v2/Users?filter=${URLENCODED_FILTER}" \ -H "accept: application/scim+json" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" | jq fi echo

delete_user.sh

#!/bin/sh VERTICAL=$1 TEST_ENV=$2 USERNAME=$3 if [ -z $VERTICAL ] || [ -z $TEST_ENV ] || [ -z $USERNAME ] || [ -z $CLIENT_SECRET ]; then echo "ERROR: Invalid parameters:" echo "USAGE: export CLIENT_SECRET=scimsecret" echo "USAGE: $0 <vertical> <test-env> <username>" if [ -z $VERTICAL ]; then echo "Missing argument <vertical>" fi if [ -z $TEST_ENV ]; then echo "Missing argument <test-env>" fi if [ -z $USERNAME ]; then echo "Missing argument <username>" fi if [ -z $CLIENT_SECRET ]; then echo "Missing environment variable CLIENT_SECRET" fi exit 1 fi echo "-----------------------------------------------------------------------------------------------------------------" echo " VERTICAL $VERTICAL - TEST environment: $TEST_ENV" echo "-----------------------------------------------------------------------------------------------------------------" REALM=$VERTICAL TOKENS_JSON=$( curl -H "Content-Type: application/x-www-form-urlencoded" \ -X POST "https://auth.${VERTICAL}.${TEST_ENV}.buypass.no/auth/realms/${REALM}/protocol/openid-connect/token" \ -d "grant_type=client_credentials&client_id=scim-api-client&client_secret=${CLIENT_SECRET}" 2>/dev/null ) # Get the Access Token (using the jq tool) ACCESS_TOKEN=$(jq -r '.access_token' <<<"${TOKENS_JSON}") URLENCODED_FILTER="userName%20eq%20%22${USERNAME}%22" SCIM_USER=$(curl -X GET "https://api.${VERTICAL}.${TEST_ENV}.buypass.no/scim/v2/Users?filter=${URLENCODED_FILTER}" \ -H "accept: application/scim+json" \ -H "Authorization: Bearer ${ACCESS_TOKEN}") # Get the user UUID (using the jq tool) SCIM_USER_UUID=$(jq -r '.Resources[].id' <<<"${SCIM_USER}") if [ -z $SCIM_USER_UUID ]; then echo "User not found" exit 0 fi curl -X DELETE "https://api.${VERTICAL}.${TEST_ENV}.buypass.no/scim/v2/Users/${SCIM_USER_UUID}" \ -H "accept: application/scim+json" \ -H "Authorization: Bearer ${ACCESS_TOKEN}" echo