export SSO_IP=`kubectl get svc -A | grep "sso " | awk '{print $4}'`
export ASMUI_PASS=`kubectl get secret pfxm-asmui-creds -o json -n powerflex | jq '.data | map_values(@base64d)' | jq -r '.["keycloak-password"]'`
export PM_TOKEN=`curl -k --location --request POST "https://${SSO_IP}:8080/rest/auth/login" --header 'Accept: application/json' --header 'Content-Type: application/json' --data "{\"username\": \"asmuiuser\",\"password\": \"$ASMUI_PASS\"}" | jq -r .access_token`
export IN_IP=`kubectl get svc -A | grep -m1 rke2-ingress-nginx-controller | sort | awk '{print $5}'`

KK_ID=b151947c-b514-4997-a369-a9b76f26b050
KK_SECRET=tk_8Q~QYTj1FQYN2chWovu.M5Ph3YnIVzLwRJcoZ
TENANT_ID=945c199a-83a2-4e80-9f8c-5a91be5752dd

curl -kvvL --request POST \
  --url https://$IN_IP/rest/v1/oidc-services \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ${PM_TOKEN}" \
  --data "{
  \"name\": \"azure\",
  \"is_enabled\": true,
  \"idp_metadata_url\": \"https://login.microsoftonline.com/${TENANT_ID}/v2.0/.well-known/openid-configuration\",
  \"claims_mapper\": [
    {
      \"name\": \"email\",
      \"value\": \"email\"
    },
    {
      \"name\": \"given_name\",
      \"value\": \"firstName\"
    },
    {
      \"name\": \"preferred_username\",
      \"value\": \"username\"
    },
    {
      \"name\": \"family_name\",
      \"value\": \"lastName\"
    }
  ],
  \"client_id\": \"$KK_ID\",
  \"client_secret\": \"$KK_SECRET\",
  \"scopes\": [
    \"openid\",
    \"profile\",
    \"email\",
    \"offline_access\" 
  ],
  \"pkce_enabled\": true,
  \"code_challenge_method\": \"S256\",
  \"idp_type\": \"AzureEntraID\"
}"

