Skip to content

Commit

Permalink
systemregisterclient calls auth comp (#271)
Browse files Browse the repository at this point in the history
* systemregisterclient calls auth comp

* json and appsetting fixes

* remove local dev stuff
  • Loading branch information
simen-rekkedal authored May 24, 2024
1 parent 12580d2 commit fe55e9f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public class RegisteredSystemDTO
public string SystemVendor { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<DefaultRightsDTO> DefaultRights { get; set; } = [];
public bool SoftDeleted { get; set; } = false;
}
Original file line number Diff line number Diff line change
@@ -1,90 +1,51 @@
using Altinn.Authentication.UI.Core.SystemRegister;
using Altinn.Authentication.UI.Core.Authentication;
using Altinn.Authentication.UI.Core.SystemRegister;
using Altinn.Authentication.UI.Integration.AccessToken;
using Altinn.Authentication.UI.Integration.Configuration;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Altinn.Authentication.UI.Core.Extensions;
using System.Text.Json;
using Microsoft.Extensions.Options;

namespace Altinn.Authentication.UI.Integration.SystemRegister;

public class SystemRegisterClient : ISystemRegisterClient
{
private static async Task<List<RegisteredSystemDTO>> MockTestHelper()
private readonly ILogger _logger;
private readonly HttpClient _httpClient;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly PlatformSettings _platformSettings;
private readonly IAccessTokenProvider _accessTokenProvider;

public SystemRegisterClient(
ILogger<SystemRegisterClient> logger,
HttpClient httpClient,
IHttpContextAccessor httpContextAccessor,
IOptions<PlatformSettings> platformSettings,
IAccessTokenProvider accessTokenProvider)
{
await Task.Delay(250);

RegisteredSystemDTO regsys1 = new()
{
SystemTypeId = "4human_hr_system_2024_2",
SystemVendor = "4Human",
Description = "4Humans HR system 2024 versjon.",
DefaultRights =
[
new DefaultRightsDTO { Right = "Sykemelding - Oppgi leder", ServiceProvider = "Arbeids- og velferdsetaten (NAV)" },
new DefaultRightsDTO { Right = "Søknad om sykepenger", ServiceProvider = "Arbeids- og velferdsetaten (NAV)" }
]

};

RegisteredSystemDTO regsys2 = new()
{
SystemTypeId = "din_lokale_regnskapspartner",
SystemVendor = "Din Lokale Regnskapspartner AS",
Description = "Regnskap og Revisor tjenester",
DefaultRights =
[
new DefaultRightsDTO { Right = "MVA rapportering", ServiceProvider = "Skatteetaten" },
new DefaultRightsDTO { Right = "Årsregnskap", ServiceProvider = "Skatteetaten" }
]
};

RegisteredSystemDTO regsys3 = new()
{
SystemTypeId = "fiken_smabedrift",
SystemVendor = "Fiken",
Description = "Fiken Småbedrift pakken",
DefaultRights =
[
new DefaultRightsDTO { Right = "MVA rapportering", ServiceProvider = "Skatteetaten" },
new DefaultRightsDTO { Right = "Årsregnskap", ServiceProvider = "Skatteetaten" }
]
};

RegisteredSystemDTO regsys4 = new()
{
SystemTypeId = "visma_mva_pakke",
SystemVendor ="Visma",
Description = "Visma MVA rapportering",
DefaultRights =
[
new DefaultRightsDTO { Right = "MVA rapportering", ServiceProvider = "Skatteetaten" }
]
_logger = logger;
_httpContextAccessor = httpContextAccessor;
_platformSettings = platformSettings.Value;
_accessTokenProvider = accessTokenProvider;
httpClient.BaseAddress = new Uri(_platformSettings!.ApiAuthenticationEndpoint!);
httpClient.DefaultRequestHeaders.Add(_platformSettings.SubscriptionKeyHeaderName, _platformSettings.SubscriptionKey);
_httpClient = httpClient;
}

};
public async Task<List<RegisteredSystemDTO>> GetListRegSys(CancellationToken cancellationToken = default)
{
string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext!, _platformSettings.JwtCookieName!)!;
string endpointUrl = $"systemregister";
var accessToken = await _accessTokenProvider.GetAccessToken();

RegisteredSystemDTO regsys5 = new()
{
SystemTypeId = "visma_skatt_totalpakke",
SystemVendor ="Visma",
Description = "Visma Totalpakke for alle skatterapporterings behov",
DefaultRights =
[
new DefaultRightsDTO { Right = "MVA rapportering", ServiceProvider = "Skatteetaten" },
new DefaultRightsDTO { Right = "Årsregnskap", ServiceProvider = "Skatteetaten" },
new DefaultRightsDTO { Right = "Bytte av Revisor", ServiceProvider = "Skatteetaten" },
new DefaultRightsDTO { Right = "Levere Lakselus", ServiceProvider = "Mattilsynet" },
]
};
HttpResponseMessage response = await _httpClient.GetAsync(token, endpointUrl, accessToken);

List<RegisteredSystemDTO> theList = new()
if (response.IsSuccessStatusCode)
{
regsys1,
regsys2,
regsys3,
regsys4,
regsys5
};

return theList;
}

public async Task<List<RegisteredSystemDTO>> GetListRegSys(CancellationToken cancellationToken)
{
return await MockTestHelper();
return JsonSerializer.Deserialize<List<RegisteredSystemDTO>>(await response.Content.ReadAsStringAsync(cancellationToken), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true})!;
}
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ public async Task<ActionResult> Post([FromBody] SystemUserDescriptor newSystemUs
var usr = await _systemUserService.PostNewSystemUserDescriptor(partyId, newSystemUserDescriptor, cancellationToken);
if (usr is not null)
{
SystemUserDTO dto = new()
{
Id = usr.Id,
IntegrationTitle = usr.Title,
ClientId = usr.ClientId,
Created = usr.Created,
Description = usr.Description,
OwnedByPartyId = usr.OwnedByPartyId,
ProductName = usr.SystemType,
ServiceOwner = "",
SupplierName = "",
SupplierOrgno = ""
};
return Ok(usr);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"PlatformSettings": {
"ApiAccessManagementEndpoint": "http://localhost:5117/accessmanagement/api/v1/",
"ApiAuthenticationEndpoint": "http://localhost:5101/authentication/api/v1/",
"ApiAuthenticationEndpoint": "https://localhost:44377/authentication/api/v1/",
"ApiProfileEndpoint": "http://localhost:5101/profile/api/v1/",
"JwtCookieName": "AltinnStudioRuntime",
"OpenIdWellKnownEndpoint": "http://localhost:5101/authentication/api/v1/",
Expand Down

0 comments on commit fe55e9f

Please sign in to comment.