Skip to content

Instantly share code, notes, and snippets.

@alexkappa
Created June 12, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkappa/255b029d39694904d31ba9ac6b182265 to your computer and use it in GitHub Desktop.
Save alexkappa/255b029d39694904d31ba9ac6b182265 to your computer and use it in GitHub Desktop.
Auth0 clean-up script
#!/usr/bin/env bash
AUTH0_DOMAIN=<your-auth0-domain>
AUTH0_TOKEN=<your-auth0-token>
function client_list() {
curl -sS \
-H "Authorization: Bearer $AUTH0_TOKEN" \
"https://$AUTH0_DOMAIN/api/v2/clients?fields=client_id,name&include_fields=true&_=$(date +%s)" |\
jq -r -c -M '.[]'
}
function client_delete() {
local client_id=$1
curl -sS \
-X DELETE \
-H "Authorization: Bearer $AUTH0_TOKEN" \
"https://$AUTH0_DOMAIN/api/v2/clients/$client_id"
}
function main() {
while read -r client; do
client_id=$(echo $client | jq -r '.client_id')
client_name=$(echo $client | jq -r '.name')
if [[ $client_name = *"Test"* ]]; then
echo "deleting: $client"
client_delete $client_id
fi
done <<< "$(client_list)"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment