Magendran V
Magendran V

Reputation: 1417

Delete user in AAD B2C using Active directory graph client

I have used below code to delete a user from Azure active directory B2C.

Uri servicePointUri = new Uri("https://graph.windows.net");

Uri serviceRoot = new Uri(servicePointUri, "xxxx.onmicrosoft.com");

var activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async () => await GetAccessToken());

var myUser = new Microsoft.Azure.ActiveDirectory.GraphClient.User()
                {
                    ObjectId = "63ca9c1d-2bd0-4a6b-8bf6-b850b16ed50b"
                };

await myUser.DeleteAsync();

But I have ended up with exception message "Not Initialized".

Can some one tell me what is the issue with this?

Upvotes: 2

Views: 922

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

You probably have to retrieve the user you want to delete first. E. g.:

var user = await Client.Users.Where(u => u.ObjectId.Equals("63ca9c1d-2bd0-4a6b-8bf6-b850b16ed50b"))).ExecuteSingleAsync();
await user.DeleteAsync();

Upvotes: 3

Related Questions