Skip to content

Commit

Permalink
Feature/accounts api v2 (#11)
Browse files Browse the repository at this point in the history
* Generated API v2

* chore: Update JWK retrieval logic in ApplicationSettings

* commit again

* onlyprimaryowner=false, fixed flatfile etc

---------

Co-authored-by: Nikolai Maasø Lunde <nikolai.maaso.lunde@digdir.no>
  • Loading branch information
erlendoksvoll and nlundee authored Jun 17, 2024
1 parent 0616dc0 commit 97197ec
Show file tree
Hide file tree
Showing 13 changed files with 4,602 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Altinn.ApiClients.Maskinporten" Version="9.1.0" />
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
<PackageReference Include="Dan.Common" Version="1.5.0" />
<PackageReference Include="FileHelpers" Version="3.5.2" />
Expand All @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.6" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.6.0" />
<PackageReference Include="NJsonSchema" Version="11.0.0" />
<PackageReference Include="NJsonSchema" Version="11.0.1" />
<PackageReference Include="Polly" Version="8.4.0" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageReference Include="Polly.Caching.Distributed" Version="3.0.1" />
Expand Down
3 changes: 2 additions & 1 deletion src/Altinn.Dan.Plugin.Banking/Clients/KARClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public async System.Threading.Tasks.Task<ListCustomerRelation> GetCustomerRelati
{
urlBuilder_.Append(System.Uri.EscapeDataString("toDate") + "=").Append(System.Uri.EscapeDataString(ConvertToString(toDate, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
}

urlBuilder_.Append(System.Uri.EscapeDataString("onlyPrimaryOwner") + "=").Append(System.Uri.EscapeDataString(ConvertToString(false, System.Globalization.CultureInfo.InvariantCulture))).Append("&");
urlBuilder_.Length--;

var client_ = _httpClient;
Expand All @@ -111,7 +113,6 @@ public async System.Threading.Tasks.Task<ListCustomerRelation> GetCustomerRelati
request_.Headers.TryAddWithoutValidation("AccountInfoRequestID", ConvertToString(accountInfoRequestID, System.Globalization.CultureInfo.InvariantCulture));
request_.Method = new System.Net.Http.HttpMethod("GET");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

PrepareRequest(client_, request_, urlBuilder_);

var url_ = urlBuilder_.ToString();
Expand Down
2,839 changes: 2,839 additions & 0 deletions src/Altinn.Dan.Plugin.Banking/Clients/V2/BankClient_v2.cs

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Jose;

namespace Altinn.Dan.Plugin.Banking.Clients.V2;
public partial class Bank_v2
{
public X509Certificate2 DecryptionCertificate { get; set; }

/// <summary>
/// The bank sends a encrypted payload, use the ProcessResponse-mechanism to decrypt before further processing
/// </summary>
/// <param name="client">Http client</param>
/// <param name="response">Response from bank</param>
// ReSharper disable once UnusedParameterInPartialMethod
partial void ProcessResponse(HttpClient client, HttpResponseMessage response)
{
var Aa = 1;

Check warning on line 22 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The variable 'Aa' is assigned but its value is never used

Check warning on line 22 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The variable 'Aa' is assigned but its value is never used

Check warning on line 22 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The variable 'Aa' is assigned but its value is never used

Check warning on line 22 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The variable 'Aa' is assigned but its value is never used


if (!response.IsSuccessStatusCode)
return;

bool isAppJose = false;

if (response.Headers.TryGetValues("content-type", out IEnumerable<string?> headervalues))

Check warning on line 30 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs

View workflow job for this annotation

GitHub Actions / run / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
isAppJose = headervalues.Any(x => x == "application/jose");
}

var jwt = response.Content.ReadAsStringAsync().Result;
var decryptedContent =
JWT.Decode(jwt,
DecryptionCertificate
.GetRSAPrivateKey()); //, JweAlgorithm.RSA_OAEP_256, JweEncryption.A128CBC_HS256);

response.Content = new StringContent(decryptedContent, Encoding.UTF8);
}

partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url)
{
var a = url;
}
}
19 changes: 19 additions & 0 deletions src/Altinn.Dan.Plugin.Banking/Config/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class ApplicationSettings
private static X509Certificate2 _altinnCertificate;
private static X509Certificate2 _oedDecryptCert;

public static string BankingJwkName { get; set; }

public ApplicationSettings()
{
ApplicationConfig = this;
Expand Down Expand Up @@ -64,9 +66,26 @@ public X509Certificate2 OedDecryptCert

public bool UseProxy { get; set; }


public string EndpointsResourceFile { get; set; }

public bool UseTestEndpoints { get; set; }

public string _jwk
{
get; set;
}

public string Jwk
{
get
{
return _jwk ?? new PluginKeyVault(KeyVaultName).Get(BankingJwkName).Result;
}
set
{
_jwk = value;
}
}
}
}
16 changes: 14 additions & 2 deletions src/Altinn.Dan.Plugin.Banking/Models/BankResponse.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Altinn.Dan.Plugin.Banking.Clients;
using System;
using System.Collections.Generic;

using Altinn.Dan.Plugin.Banking.Clients.V2;
using AccountDetail = Altinn.Dan.Plugin.Banking.Clients.AccountDetail;
using Transaction = Altinn.Dan.Plugin.Banking.Clients.Transaction;
using AccountDetailV2 = Altinn.Dan.Plugin.Banking.Clients.V2.AccountDetail;
using TransactionV2 = Altinn.Dan.Plugin.Banking.Clients.V2.Transaction;
namespace Altinn.Dan.Plugin.Banking.Models
{
public class BankResponse
Expand All @@ -25,4 +28,13 @@ public class Account
public decimal AccountAvailableBalance { get; set; }
public decimal AccountBookedBalance { get; set; }
}

public class AccountV2
{
public string AccountNumber { get; set; } // Seperate property by now. Copy of AccountDetail.AccountIdentifier
public AccountDetailV2 AccountDetail { get; set; } // Not mapped to internal by now
public ICollection<TransactionV2> Transactions { get; set; } // Not mapped to internal by now
public decimal AccountAvailableBalance { get; set; }
public decimal AccountBookedBalance { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Altinn.Dan.Plugin.Banking/Models/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class EndpointV2
public string OrgNummer { get; set; }

[FieldOptional]
[FieldQuoted(QuoteMode.OptionalForBoth)]
public string Navn { get; set; }

[FieldOptional]
Expand Down
File renamed without changes.
Loading

0 comments on commit 97197ec

Please sign in to comment.