Skip to content

Commit

Permalink
SH0 - adding a profile controller
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Williams committed Jul 21, 2021
1 parent ba7b239 commit 0493f69
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@
namespace NICE.Identity.Authorisation.WebAPI.Controllers
{
[Route("api/[controller]")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] //can't add the UserAdministration policy at this level as the find users and find roles actions don't need it.
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ApiController]
public class UserProfileController : ControllerBase
{
private readonly ILogger<UsersController> _logger;
private readonly ILogger<UserProfileController> _logger;
private readonly IUsersService _usersService;
private readonly IHttpContextAccessor _httpContextAccessor;

public UserProfileController(IUsersService usersService, ILogger<UsersController> logger)
private const string NameIdentifierClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";

public UserProfileController(IUsersService usersService, ILogger<UserProfileController> logger, IHttpContextAccessor httpContextAccessor)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_usersService = usersService ?? throw new ArgumentNullException(nameof(usersService));
}
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
}

private string GetNameIdentifierFromUser()
{
var claimsPrincipal = HttpContext?.User; //todo: switch to using httpcontextaccessor..
var claimsPrincipal = _httpContextAccessor.HttpContext.User;

return claimsPrincipal.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value;
return claimsPrincipal.Claims.FirstOrDefault(c => c.Type == NameIdentifierClaimType)?.Value;
}

/// <summary>
Expand Down

2 comments on commit 0493f69

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

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

TeamCity Identity and Access Management / Identity - RoleManagementAPI Build 1001-SH-0-RegistrationSit outcome was SUCCESS
Summary: Tests passed: 91 Build time: 00:07:54

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

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

TeamCity Identity and Access Management / Identity - RoleManagementAPI Build 1022-SH-0-RegistrationSit outcome was SUCCESS
Summary: Tests passed: 91 Build time: 00:02:42

Please sign in to comment.