-
Notifications
You must be signed in to change notification settings - Fork 1
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
API endpoint for getting UserProfile by username #105
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
87ff2de
API endpoint for getting UserProfile by username
2f42255
fixed øæå testdata issue
5d4782b
- Moved implementation into separate controller for internal use only
dc14458
Forgot to set controller endpoints hidden from swagger
ad86449
Fixed wrong namespace on UserProfileLookup model
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/Altinn.Profile/Controllers/UserProfileInternalController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Threading.Tasks; | ||
using Altinn.Platform.Profile.Models; | ||
using Altinn.Profile.Models; | ||
using Altinn.Profile.Services.Interfaces; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Altinn.Profile.Controllers | ||
{ | ||
/// <summary> | ||
/// Controller for user profile API endpoints for internal consumption (e.g. Authorization) requiring neither authenticated user token nor access token authorization. | ||
/// </summary> | ||
[Route("profile/api/v1/internal/user")] | ||
[ApiExplorerSettings(IgnoreApi = true)] | ||
[Consumes("application/json")] | ||
[Produces("application/json")] | ||
public class UserProfileInternalController : Controller | ||
{ | ||
private readonly IUserProfiles _userProfilesWrapper; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UserProfileInternalController"/> class | ||
/// </summary> | ||
/// <param name="userProfilesWrapper">The users wrapper</param> | ||
public UserProfileInternalController(IUserProfiles userProfilesWrapper) | ||
{ | ||
_userProfilesWrapper = userProfilesWrapper; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the user profile for a given user identified by one of the available types of user identifiers: | ||
/// UserId (from Altinn 2 Authn UserProfile) | ||
/// Username (from Altinn 2 Authn UserProfile) | ||
/// SSN/Dnr (from Freg) | ||
/// Uuid (from Altinn 2 Party/UserProfile implementation will be added later) | ||
/// </summary> | ||
/// <param name="userProfileLookup">Input model for providing one of the supported lookup parameters</param> | ||
/// <returns>User profile of the given user</returns> | ||
[HttpPost] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
public async Task<ActionResult<UserProfile>> Get([FromBody] UserProfileLookup userProfileLookup) | ||
{ | ||
UserProfile result; | ||
if (userProfileLookup != null && userProfileLookup.UserId != 0) | ||
{ | ||
result = await _userProfilesWrapper.GetUser(userProfileLookup.UserId); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(userProfileLookup?.Username)) | ||
{ | ||
result = await _userProfilesWrapper.GetUserByUsername(userProfileLookup.Username); | ||
} | ||
else if (!string.IsNullOrWhiteSpace(userProfileLookup?.Ssn)) | ||
{ | ||
result = await _userProfilesWrapper.GetUser(userProfileLookup.Ssn); | ||
} | ||
else | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
if (result == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return Ok(result); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Altinn.Profile.Models | ||
{ | ||
/// <summary> | ||
/// Input model for internal UserProfile lookup requests, where one of the lookup identifiers available must be set for performing the lookup request: | ||
/// UserId (from Altinn 2 Authn UserProfile) | ||
/// Username (from Altinn 2 Authn UserProfile) | ||
/// SSN/Dnr (from Freg) | ||
/// Uuid (from Altinn 2 Party/UserProfile implementation will be added later) | ||
/// </summary> | ||
public class UserProfileLookup | ||
{ | ||
/// <summary> | ||
/// Gets or sets the users UserId if the lookup is to be performed based on this identifier | ||
/// </summary> | ||
public int UserId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the users Username if the lookup is to be performed based on this identifier | ||
/// </summary> | ||
public string Username { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the users social security number or d-number from Folkeregisteret if the lookup is to be performed based on this identifier | ||
/// </summary> | ||
public string Ssn { get; set; } | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Log entries created from user input High