Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

how to list oidc clients from lightwave sts

Sriram Nambakam edited this page Feb 5, 2018 · 1 revision

Notes

  • As a pre-requisite, retrieve the OIDC token from Lightwave using code
  • This program depends on jq and curl
#!/bin/bash

LW_TENANT=
LW_SERVER=
LW_PORT=443
CRED_CACHE_PATH="$HOME/.lightwave_tokens"

showUsage()
{
    echo "Usage: lw-get-oidc-clients -t <tenant>"
    echo "                           -s <server>"
    echo "                           [ -p <port>]"
}

getEncodedValue()
{
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] )
            o="${c}"
            ;;
        * )
            printf -v o '%%%02x' "'$c'"
            ;;
     esac
     encoded+="${o}"
  done
  echo "${encoded}"
}

while getopts t:s:p: o
do
    case "$o" in
        t)
            LW_TENANT="$OPTARG"
            ;;
        s)
            LW_SERVER="$OPTARG"
            ;;
        p)
            LW_PORT="$OPTARG"
            ;;
        [?])
            showUsage
            exit 1
    esac
done

if [ -z "$LW_TENANT" ]; then
    echo "Error: The Lightwave Tenant was not specified"
    showUsage
    exit 1
fi

if [ -z "$LW_SERVER" ]; then
    echo "Error: The Lightwave Server was not specified"
    showUsage
    exit 1
fi

if [ -z "$LW_PORT" ]; then
    echo "Error: The Lightwave Port was not specified"
    showUsage
    exit 1
fi

if [ ! -f $CRED_CACHE_PATH ]; then
    echo "Error: No authentication tokens found. Please login and try again."
    showUsage
    exit 1
fi

LW_TOKEN=$(jq -r '.access_token' $CRED_CACHE_PATH)

if [ -z "$LW_TOKEN" ]; then
    echo "Error: Invalid or no OIDC token found in $CRED_CACHE_PATH"
    echo "Please retry after acquiring a valid OIDC token from Lightwave"
    exit 2
fi

encoded_tenant=$(getEncodedValue $LW_TENANT)

url="https://$LW_SERVER:$LW_PORT/idm/post/tenant/$encoded_tenant/oidcclient"

headers=(
     -H "accept: application/json"
     -H "Authorization: Bearer $LW_TOKEN"
)

curl -k -X POST "$url" "${headers[@]}" | jq '.'
Clone this wiki locally