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

how to delete oidc client for lightwave ui

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

Notes

  • As a pre-requisite, retrieve the OIDC token from Lightwave using code
  • The client id of an existing OIDC client can be listed using code
  • This program depends on jq and curl
#!/bin/bash

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

showUsage()
{
    echo "Usage: lw-unregister-oidc-client -t <tenant>"
    echo "                                 -s <server>"
    echo "                                 [ -p <port>]"
    echo "                                 -c <client_id>"
}

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:c: o
do
    case "$o" in
        t)
            LW_TENANT="$OPTARG"
            ;;
        s)
            LW_SERVER="$OPTARG"
            ;;
        p)
            LW_PORT="$OPTARG"
            ;;
        c)
            CLIENT_ID="$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 [ -z "$CLIENT_ID" ]; then
    echo "Error: The Client ID 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)
encoded_client_id=$(getEncodedValue $CLIENT_ID)

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

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

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