Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete user identity server endpoint and delete profile and forms api endpoint #442

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using IdentityServer.Data;
using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Services;
using IdentityServer4.Validation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace StamAcasa.IdentityServer.Quickstart.Account
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class DeleteAccountController : ControllerBase
{
private readonly UserManager<ApplicationUser> _userManager;

public DeleteAccountController(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}

[HttpPost]
public async Task<IActionResult> DeleteAccountAsync([FromBody] DeleteAccountModel model)
{
var user = await _userManager.FindByNameAsync(model.Username);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not provide info to anyone if a user with specified username exists or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree with this one.
Can you please make the change @irinel-nistor ?

if (user == null || !await _userManager.CheckPasswordAsync(user, model.Password))
{
return new UnauthorizedResult();
}

var response = await _userManager.DeleteAsync(user);
if (!response.Succeeded)
{
return StatusCode(StatusCodes.Status500InternalServerError, $"Unexpected error occurred deleting user with ID '{user.Id}'.");
}

return Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace StamAcasa.IdentityServer.Quickstart.Account
{
public class DeleteAccountModel
{
public string Username { get; set; }

public string Password { get; set; }
}
}