Created
November 3, 2016 14:47
-
-
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#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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