-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sr at21 integration test config4 (#234)
* unauth systemregister * reauth systemregister * add profileclient and it's dependencies * access token etc towards profile api * fix comment * init * forgot to switch to the real client from the mock * userprofile and partyclient fixes * removed unused method * fix * quickfix * nudge
- Loading branch information
1 parent
8501d92
commit 3e38190
Showing
10 changed files
with
83 additions
and
45 deletions.
There are no files selected for viewing
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
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
68 changes: 61 additions & 7 deletions
68
...Altinn.Authentication.UI/Altinn.Authentication.UI.Integration/UserProfiles/PartyClient.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 |
---|---|---|
@@ -1,19 +1,73 @@ | ||
using Altinn.Authentication.UI.Core.UserProfiles; | ||
using Altinn.Authentication.UI.Core.Authentication; | ||
using Altinn.Authentication.UI.Core.UserProfiles; | ||
using Altinn.Authentication.UI.Integration.Configuration; | ||
using Altinn.Authentication.UI.Core.Extensions; | ||
using Altinn.Platform.Register.Models; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Altinn.Authentication.UI.Integration.UserProfiles; | ||
|
||
/// <summary> | ||
/// Proxy implementation for parties | ||
/// </summary> | ||
[ExcludeFromCodeCoverage] | ||
public class PartyClient : IPartyClient | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly HttpClient _client; | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly PlatformSettings _platformSettings; | ||
private readonly JsonSerializerOptions _serializerOptions = | ||
new() { PropertyNameCaseInsensitive = true }; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LookupClient"/> class | ||
/// </summary> | ||
/// <param name="httpClient">HttpClient from default httpclientfactory</param> | ||
/// <param name="logger">the logger</param> | ||
/// <param name="httpContextAccessor">handler for http context</param> | ||
/// <param name="platformSettings">the platform setttings</param> | ||
public PartyClient( | ||
HttpClient httpClient, | ||
ILogger<PartyClient> logger, | ||
IHttpContextAccessor httpContextAccessor, | ||
IOptions<PlatformSettings> platformSettings) | ||
{ | ||
_logger = logger; | ||
_httpContextAccessor = httpContextAccessor; | ||
_platformSettings = platformSettings.Value; | ||
httpClient.BaseAddress = new Uri(_platformSettings.ApiAccessManagementEndpoint); | ||
_client = httpClient; | ||
_serializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<Party> GetPartyFromReporteeListIfExists(int partyId) | ||
{ | ||
Party mock = new() | ||
try | ||
{ | ||
PartyId = 5001, | ||
OrgNumber = "123456789MVA", | ||
Name = "Framifrå Bedrift AS" | ||
}; | ||
string endpointUrl = $"authorizedparty/{partyId}?includeAltinn2=true"; | ||
string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext!, _platformSettings.JwtCookieName!)!; | ||
|
||
return mock; | ||
HttpResponseMessage response = await _client.GetAsync(token, endpointUrl); | ||
|
||
if ( response.StatusCode == System.Net.HttpStatusCode.OK ) | ||
{ | ||
string responseContent = await response.Content.ReadAsStringAsync(); | ||
return JsonSerializer.Deserialize<Party>(responseContent, _serializerOptions)!; | ||
} | ||
|
||
return null!; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, "Authentication.UI // PartyClient // GetPartyFromReporteeListIfExists // Exception"); | ||
throw; | ||
} | ||
} | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/appsettings.AT21.json
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