headers,
string payloadJson,
string signingKey,
- JwsAlgorithm? jwsAlgorithm)
+ JwsAlgorithm? jwsAlgorithm,
+ bool encodePayload = true,
+ bool detachPayload = false)
{
signingKey.ArgNotNull(nameof(signingKey));
@@ -28,11 +30,18 @@ public static string CreateJwt(
{
CertificateFactories.ImportPrivateKey(signingKey, ref rsa);
+ var options = new JwtOptions
+ {
+ EncodePayload = encodePayload,
+ DetachPayload = detachPayload
+ };
+
string result = JWT.Encode(
payloadJson,
rsa,
jwsAlgorithm ?? JwsAlgorithm.PS256,
- headers);
+ headers,
+ options: options);
return result;
}
finally
diff --git a/src/OpenBanking.Library.Connector.Web/ExternalApiHttpErrorExceptionFilter.cs b/src/OpenBanking.WebApp.Connector/Filters/ExternalApiHttpErrorExceptionFilter.cs
similarity index 63%
rename from src/OpenBanking.Library.Connector.Web/ExternalApiHttpErrorExceptionFilter.cs
rename to src/OpenBanking.WebApp.Connector/Filters/ExternalApiHttpErrorExceptionFilter.cs
index 0e287198a..2f8b121d0 100644
--- a/src/OpenBanking.Library.Connector.Web/ExternalApiHttpErrorExceptionFilter.cs
+++ b/src/OpenBanking.WebApp.Connector/Filters/ExternalApiHttpErrorExceptionFilter.cs
@@ -1,4 +1,4 @@
-// Licensed to Finnovation Labs Limited under one or more agreements.
+// Licensed to Finnovation Labs Limited under one or more agreements.
// Finnovation Labs Limited licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -10,7 +10,7 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Net.Http.Headers;
-namespace FinnovationLabs.OpenBanking.Library.Connector.Web;
+namespace FinnovationLabs.OpenBanking.WebApp.Connector.Filters;
public class ExternalApiHttpErrorExceptionFilter : IActionFilter, IOrderedFilter
{
@@ -18,25 +18,15 @@ public void OnActionExecuting(ActionExecutingContext context) { }
public void OnActionExecuted(ActionExecutedContext context)
{
- if (context.Exception is ExternalApiAccessException httpResponseException)
+ if (context.Exception is ExternalApiResponseDeserialisationException httpResponseException)
{
- int statusCode;
- if (context.Exception is ExternalApiResponseDeserialisationException ex)
- {
- statusCode = 500;
- }
- else
- {
- statusCode = httpResponseException.ResponseStatusCode;
- }
-
var jsonObject = new JsonObject
{
["title"] = httpResponseException.Message,
["detail"] =
$"External API endpoint responded with HTTP status code {httpResponseException.ResponseStatusCode}. See properties " +
"'endpointHttpMethod', 'endpointUrl' and 'endpointResponse' for more details.",
- ["status"] = statusCode,
+ ["status"] = 500,
["endpointHttpMethod"] = httpResponseException.RequestHttpMethod,
["endpointUrl"] = httpResponseException.RequestUrl
};
@@ -46,22 +36,22 @@ public void OnActionExecuted(ActionExecutedContext context)
jsonObject["endpointFapiInteractionId"] = httpResponseException.XFapiInteractionId;
}
- if (context.Exception is ExternalApiResponseDeserialisationException ex2)
- {
- jsonObject["deserialisationError"] = ex2.DeserialisationErrorMessage;
- }
+ jsonObject["deserialisationError"] = httpResponseException.DeserialisationErrorMessage;
- JsonNode? responseMessage;
- try
- {
- responseMessage = JsonNode.Parse(httpResponseException.ResponseMessage);
- }
- catch
+ if (httpResponseException.ExposeSuccessResponseBody)
{
- responseMessage = httpResponseException.ResponseMessage;
- }
+ JsonNode? responseMessage;
+ try
+ {
+ responseMessage = JsonNode.Parse(httpResponseException.ResponseMessage);
+ }
+ catch (JsonException)
+ {
+ responseMessage = httpResponseException.ResponseMessage;
+ }
- jsonObject["endpointResponse"] = responseMessage;
+ jsonObject["endpointResponse"] = responseMessage;
+ }
string jsonString = JsonSerializer.Serialize(jsonObject);
@@ -71,7 +61,7 @@ public void OnActionExecuted(ActionExecutedContext context)
{
Content = jsonString,
ContentType = mediaTypeHeaderValue.ToString(),
- StatusCode = statusCode
+ StatusCode = 500
};
context.ExceptionHandled = true;
diff --git a/src/OpenBanking.Library.Connector.Web/GlobalExceptionFilter.cs b/src/OpenBanking.WebApp.Connector/Filters/GlobalExceptionFilter.cs
similarity index 53%
rename from src/OpenBanking.Library.Connector.Web/GlobalExceptionFilter.cs
rename to src/OpenBanking.WebApp.Connector/Filters/GlobalExceptionFilter.cs
index 58b172dcf..5895d6a7f 100644
--- a/src/OpenBanking.Library.Connector.Web/GlobalExceptionFilter.cs
+++ b/src/OpenBanking.WebApp.Connector/Filters/GlobalExceptionFilter.cs
@@ -1,13 +1,14 @@
-// Licensed to Finnovation Labs Limited under one or more agreements.
+// Licensed to Finnovation Labs Limited under one or more agreements.
// Finnovation Labs Limited licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using FinnovationLabs.OpenBanking.Library.Connector.Extensions;
using FinnovationLabs.OpenBanking.Library.Connector.Fluent;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
-namespace FinnovationLabs.OpenBanking.Library.Connector.Web;
+namespace FinnovationLabs.OpenBanking.WebApp.Connector.Filters;
public class GlobalExceptionFilter(ProblemDetailsFactory problemDetailsFactory) : IExceptionFilter
{
@@ -15,30 +16,23 @@ public void OnException(ExceptionContext context)
{
if (context.Exception is HttpResponseException exception)
{
+ ServerError serverError = exception.ServerError;
ProblemDetails problemDetails = problemDetailsFactory.CreateProblemDetails(
context.HttpContext,
- exception.StatusCode,
- GetTitleString(exception.Title),
+ serverError.StatusCode,
+ serverError.Title,
null,
- exception.Message);
- if (exception.Extensions is not null)
+ serverError.Detail);
+
+ foreach ((string key, object? value) in serverError.Extensions)
{
- problemDetails.Extensions = exception.Extensions;
+ problemDetails.Extensions[key.ToCamelCase()] = value;
}
- context.Result = new ObjectResult(problemDetails) { StatusCode = exception.StatusCode };
- context.ExceptionHandled = true;
- }
- }
+ problemDetails.Extensions["serverErrorType"] = serverError.ServerErrorType.ToString().ToCamelCase();
- private static string GetTitleString(ProblemDetailsTitle title)
- {
- var titleString = title.ToString();
- if (string.IsNullOrEmpty(titleString) ||
- char.IsLower(titleString[0]))
- {
- return titleString;
+ context.Result = new ObjectResult(problemDetails) { StatusCode = serverError.StatusCode };
+ context.ExceptionHandled = true;
}
- return char.ToLower(titleString[0]) + titleString[1..];
}
}
diff --git a/src/OpenBanking.WebApp.Connector/OpenBanking.WebApp.Connector.csproj b/src/OpenBanking.WebApp.Connector/OpenBanking.WebApp.Connector.csproj
index ef4671fd3..513402721 100644
--- a/src/OpenBanking.WebApp.Connector/OpenBanking.WebApp.Connector.csproj
+++ b/src/OpenBanking.WebApp.Connector/OpenBanking.WebApp.Connector.csproj
@@ -7,7 +7,7 @@
aa921213-9461-4f9e-8fec-153624ec67ad
FinnovationLabs.OpenBanking.WebApp.Connector
FinnovationLabs.OpenBanking.WebApp.Connector
- 18.2.0
+ 20.0.0
Finnovation Labs Limited and Contributors
Finnovation Labs Limited
false
@@ -16,16 +16,18 @@
-
-
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
+
+
diff --git a/src/OpenBanking.WebApp.Connector/Program.cs b/src/OpenBanking.WebApp.Connector/Program.cs
index 62083e980..2d1e823c3 100644
--- a/src/OpenBanking.WebApp.Connector/Program.cs
+++ b/src/OpenBanking.WebApp.Connector/Program.cs
@@ -5,16 +5,15 @@
using System.Reflection;
using FinnovationLabs.OpenBanking.Library.Connector.GenericHost.Extensions;
using FinnovationLabs.OpenBanking.Library.Connector.Persistence;
-using FinnovationLabs.OpenBanking.Library.Connector.Web;
using FinnovationLabs.OpenBanking.Library.Connector.Web.Extensions;
using FinnovationLabs.OpenBanking.WebApp.Connector.Extensions;
+using FinnovationLabs.OpenBanking.WebApp.Connector.Filters;
using Microsoft.OpenApi;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
+using OpenTelemetry.Trace;
using AccountAndTransactionModelsPublic =
FinnovationLabs.OpenBanking.Library.BankApiModels.UkObRw.V4p0.NSwagAisp.Models;
-using ServiceCollectionExtensionsWeb =
- FinnovationLabs.OpenBanking.Library.Connector.Web.Extensions.ServiceCollectionExtensions;
using ServiceCollectionExtensionsGenericHost =
FinnovationLabs.OpenBanking.Library.Connector.GenericHost.Extensions.ServiceCollectionExtensions;
@@ -33,9 +32,9 @@
builder.Services
// Add .NET generic host app services
- .AddGenericHostServices(builder.Configuration)
+ .AddGenericHostServices(builder.Configuration, serviceVersion, b => b.AddAspNetCoreInstrumentation())
// Add .NET web host app services
- .AddWebHostServices(builder.Configuration, serviceVersion)
+ .AddWebHostServices(serviceVersion)
// Configure Swagger
.AddSwaggerGen(
options =>
@@ -80,15 +79,6 @@
Version = serviceVersion,
Description = "Auth Contexts API for Open Banking Connector Web App"
});
- options.SwaggerDoc(
- "test",
- new OpenApiInfo
- {
- Title = "Testing (non-production) API",
- Version = serviceVersion,
- Description =
- "Testing API for Open Banking Connector Web App. Endpoints should not be used in production."
- });
// Add XML from this assembly
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
@@ -102,10 +92,6 @@
// Add XML from OpenBankingLibrary.GenericHost
xmlFilename = $"{typeof(ServiceCollectionExtensionsGenericHost).GetTypeInfo().Assembly.GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
- // Add XML from OpenBankingLibrary.Web
- xmlFilename =
- $"{typeof(ServiceCollectionExtensionsWeb).GetTypeInfo().Assembly.GetName().Name}.xml";
- options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
})
.AddSwaggerGenNewtonsoftSupport()
// Add memory cache
@@ -130,7 +116,9 @@
builder
.Logging
- .AddWebHostLogging(builder.Configuration, serviceVersion);
+ .ClearProviders()
+ .AddConsole()
+ .AddGenericHostLogging(builder.Configuration, serviceVersion);
// Build app
WebApplication app = builder.Build();
@@ -148,9 +136,6 @@
// Add local static files
app.UseStaticFiles();
-// Add web host static files
-app.UseWebHostStaticFiles();
-
// Add Swagger generation
app.UseSwagger();
app.UseSwaggerUI(
@@ -161,7 +146,6 @@
c.SwaggerEndpoint("/swagger/pisp/swagger.json", "Payment Initiation API");
c.SwaggerEndpoint("/swagger/vrp/swagger.json", "Variable Recurring Payments API");
c.SwaggerEndpoint("/swagger/auth-contexts/swagger.json", "Auth Contexts API");
- c.SwaggerEndpoint("/swagger/test/swagger.json", "Testing (non-production) API");
});
// Add controller endpoints
diff --git a/src/OpenBanking.WebApp.Connector/wwwroot/index.html b/src/OpenBanking.WebApp.Connector/wwwroot/index.html
index 6585bd7ac..0aabad6e8 100644
--- a/src/OpenBanking.WebApp.Connector/wwwroot/index.html
+++ b/src/OpenBanking.WebApp.Connector/wwwroot/index.html
@@ -34,8 +34,7 @@ Open Banking Connector
Open-source Open Banking connectivity
Contents
- OpenAPI documentation
- Testing (non-production): Fragment redirect page
+ OpenAPI documentation