Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DavidStrickland0/97300fca392848df5afdba260d5018ea to your computer and use it in GitHub Desktop.
Save DavidStrickland0/97300fca392848df5afdba260d5018ea to your computer and use it in GitHub Desktop.
Purges ALL users from a Auth0 Account via the management API using C#
using Auth0.Core.Http;
using Auth0.ManagementApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Auth0Purge
{
class Program
{
static void Main(string[] args)
{
if(args.Count()!=2)
{
Console.Write("Example: Auth0Purge MyApp 000-000-0000apikey0000");
}
string application = args[0];
string apikey = args[1];
Uri url = new Uri($"https://{application}.auth0.com/api/v2");
var connection = new ManagementApiClient(apikey, url);
var users = connection.Users.GetAllAsync().Result ;
Console.WriteLine("About to delete {0} users from {1}. Press Y to continue.", users.Count.ToString(), application);
var confirm = Console.ReadKey();
if (confirm.Key == ConsoleKey.Y)
{
foreach (var user in users)
{
connection.Users.DeleteAsync(user.UserId).Wait();
Console.WriteLine($"{user.Email} deleted.");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment