How to pull data from Oracle IDCS (Identity Cloud Services) rest API

Updated: Nov 3, 2018



Oracle IDCS has various rest apis which can be used to pull data and you can utilize it further for data analytics. Lets see how we can pull data using simple shell scripts.

Step1: Create a parameter file "param.txt" which will contain Customer ID, Customer secret and organization url (all in new line). You can leave the environment name as it is. Please note below values are just dummy values to showcase how you need to create param file. Validate using postman if your keys are working properly before running the script.

scripts> pwd

/home/hadoop/scripts

scripts> more param.txt

CID=

61rgrjk5869bjrvrb9999rbre20

CSEC=

01rgt-atbt-4956-9e77-15rjb74756nr64

ORG=

https://idcs-9bbrtj756bjer8gbk753gbvj8f7eh3.identity.oraclecloud.com

ENV=

QUAL


Step2: At the same path create the script for pulling data in JSON format, brief description is given before each step.


#Check if parameter file exists and its parameters

#!/bin/bash

[ -f ./param.txt ] && echo "Parameter file is present" || echo "Parameter file not found!! Create param.txt with CID,CSEC,ORG,ENV details."

ENV=`head -8 ./param.txt | tail -1`

[ -z "$ENV" ] && echo "Environment variable is empty" || echo "Environment variable looks good"

case $ENV in

DEV) echo "Welcome to DEV environment!" ;;

QUAL) echo "Welcome to QUAL environment!"

CID=`head -2 ./param.txt | tail -1`

CSEC=`head -4 ./param.txt | tail -1`

ORG=`head -6 ./param.txt | tail -1`

sleep 1;;

PL) echo "Welcome to ProdLike environment!" ;;

PT) echo "Welcome to ProdTest environment!" ;;

PROD) echo "Welcome to PROD environment!" ;;

*) echo "Invalid environment selection!" ;;

esac

# Create basic_token base64, basic_token generated at https://www.base64encode.org/

basic_token=`echo -n $CID:$CSEC | base64 -w 0`

# Function to regenerate token if token test fails or expires

regenToken()

{

curl -X POST \

"$ORG/oauth2/v1/token" \

-H "Authorization: Basic $basic_token" \

-H "Cache-Control: no-cache" \

-H "Content-Type: application/x-www-form-urlencoded" \

-d "grant_type=client_credentials&scope=urn%3Aopc%3Aidm%3A__myscopes__" | awk -F[":"] '{print$2}' | awk -F[","] '{print$1}' | awk '{print substr($0, 2, length($0) - 2)}' > access_token.tmp

echo "New token is generated.. access_token refreshed!!"

}

# Testing if token is valid, if invalid generate the new token

access_token=`more access_token.tmp`