public async Task <string> DeleteUser(GraphObject graphObject)
        {
            var client   = new B2CGraphClient(clientId, clientSecret, tenant);
            var response = await client.DeleteUser(graphObject.UserId);

            return(response);
        }
Exemplo n.º 2
0
        private async Task DeleteUserAD(string objectId)
        {
            try
            {
                //Obtain B2C Settings
                var b2cDB = new ADB2CSettings()
                {
                    Id = 1
                };
                var b2cSettings = await _db.GetAsync(b2cDB);

                //Use Microsoft Graph to perform action on Azure AD B2C
                var client = new B2CGraphClient(
                    b2cSettings.AadClientId,
                    b2cSettings.AadClientSecret,
                    b2cSettings.AadTenant,
                    b2cSettings.AadGraphResourceId,
                    b2cSettings.AadGraphEndpoint,
                    b2cSettings.AadGraphVersion);
                await client.DeleteUser(objectId);
            }
            catch (Exception)
            {
                //Ignore if no AAD user is found
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete()
        {
            var userObjectIdentifier = HttpContext.User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier");

            var client = new B2CGraphClient(_tenantAdminOptions.ClientId, _tenantAdminOptions.ClientSecret, _tenantAdminOptions.Tenant);

            await client.DeleteUser(userObjectIdentifier.Value);

            return(await SignOut());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                string id = req.Query["id"];
                log.LogInformation("Query: " + req.Query);
                log.LogInformation(id);
                if (!String.IsNullOrEmpty(id))
                {
                    string tenant       = _appSettings.B2CTenantId;                       // Environment.GetEnvironmentVariable("B2CTenantId", EnvironmentVariableTarget.Process);
                    string clientId     = _appSettings.B2CGraphAccessClientId.ToString(); // Environment.GetEnvironmentVariable("B2CGraphAccessClientId", EnvironmentVariableTarget.Process);
                    string clientSecret = _appSettings.B2CGraphAccessClientSecret;        // Environment.GetEnvironmentVariable("B2CGraphAccessClientSecret", EnvironmentVariableTarget.Process);

                    B2CGraphClient client = new B2CGraphClient(clientId, clientSecret, tenant);

                    var getUserApiResponse = await client.GetUserByObjectId(id);

                    if (!String.IsNullOrEmpty(getUserApiResponse))
                    {
                        var user = JsonConvert.DeserializeObject <UserValueModel>(getUserApiResponse);
                        if (user == null || String.IsNullOrEmpty(user.objectId))
                        {
                            return(new BadRequestObjectResult(new ResponseContentModel
                            {
                                userMessage = "No such a user exist. Please check the Object Id",
                            }));
                        }
                    }
                    else
                    {
                        return(new BadRequestObjectResult(new ResponseContentModel
                        {
                            userMessage = "No such a user exist. Please check the Object Id",
                        }));
                    }

                    var status = await client.DeleteUser(id);

                    if (status)
                    {
                        return((ActionResult) new OkObjectResult(status));
                    }
                    else
                    {
                        return(new BadRequestObjectResult(new ResponseContentModel
                        {
                            userMessage = "Sorry, something happened unexpectedly. Couldn't delete the user. Please try again later."
                        }));
                    }
                }
                else
                {
                    return(new BadRequestObjectResult(new ResponseContentModel
                    {
                        userMessage = "Please pass object id of the user",
                    }));
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex.ToString());

                return(new BadRequestObjectResult(new ResponseContentModel
                {
                    userMessage = "Sorry, something happened unexpectedly. Couldn't delete the user. Please try again later.",
                    developerMessage = "See logging provider failure dependencies for exception information."
                }));
            }
        }