Compare commits
5 Commits
v1.1.0
...
cbf5ec076d
| Author | SHA1 | Date | |
|---|---|---|---|
| cbf5ec076d | |||
| a5737a510d | |||
| 2e9a3108f4 | |||
| 9c58bc2948 | |||
| edfc18d7f4 |
@@ -46,9 +46,9 @@ public abstract class AppDbContext : DbContext
|
|||||||
foreach(var entry in entries) {
|
foreach(var entry in entries) {
|
||||||
if (entry.State == EntityState.Added)
|
if (entry.State == EntityState.Added)
|
||||||
{
|
{
|
||||||
((BaseEntity)entry.Entity).DateCreated = DateTime.Now;
|
((BaseEntity)entry.Entity).DateCreated = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
((BaseEntity)entry.Entity).DateModified = DateTime.Now;
|
((BaseEntity)entry.Entity).DateModified = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Treestar.Shared.Models;
|
using Treestar.Shared.Models;
|
||||||
|
|
||||||
@@ -10,10 +11,12 @@ public abstract class ApiAccessLayer
|
|||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private readonly IAccessLayerAuthenticationProvider _authenticationProvider;
|
private readonly IAccessLayerAuthenticationProvider _authenticationProvider;
|
||||||
|
protected readonly ILogger Logger;
|
||||||
|
|
||||||
protected ApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider)
|
protected ApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider, ILogger logger)
|
||||||
{
|
{
|
||||||
_authenticationProvider = authenticationProvider;
|
_authenticationProvider = authenticationProvider;
|
||||||
|
Logger = logger;
|
||||||
var handler = new HttpClientHandler()
|
var handler = new HttpClientHandler()
|
||||||
{
|
{
|
||||||
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
||||||
@@ -26,6 +29,10 @@ public abstract class ApiAccessLayer
|
|||||||
{
|
{
|
||||||
await _authenticationProvider.AddAuthentication(message);
|
await _authenticationProvider.AddAuthentication(message);
|
||||||
var response = await _httpClient.SendAsync(message);
|
var response = await _httpClient.SendAsync(message);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
Logger.LogError("Response returned status code {statusCode} with reason {reason} and content {content}", response.StatusCode, response.ReasonPhrase, await response.Content.ReadAsStringAsync());
|
||||||
|
}
|
||||||
return new HttpResponseWrapper()
|
return new HttpResponseWrapper()
|
||||||
{
|
{
|
||||||
HttpResponseMessage = response
|
HttpResponseMessage = response
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace WebNovelPortal.AccessLayers;
|
|||||||
|
|
||||||
public class WebApiAccessLayer : ApiAccessLayer
|
public class WebApiAccessLayer : ApiAccessLayer
|
||||||
{
|
{
|
||||||
public WebApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider) : base(apiBaseUrl, authenticationProvider)
|
public WebApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider, ILogger<WebApiAccessLayer> logger) : base(apiBaseUrl, authenticationProvider, logger)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace WebNovelPortal.Controllers
|
|||||||
{
|
{
|
||||||
await HttpContext.ChallengeAsync(new AuthenticationProperties
|
await HttpContext.ChallengeAsync(new AuthenticationProperties
|
||||||
{
|
{
|
||||||
RedirectUri = redirect
|
RedirectUri = redirect,
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Treestar.Shared.AccessLayers;
|
using Treestar.Shared.AccessLayers;
|
||||||
using Treestar.Shared.Authentication.OIDC;
|
using Treestar.Shared.Authentication.OIDC;
|
||||||
@@ -10,7 +11,7 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddScoped<IAccessLayerAuthenticationProvider, BlazorAccessLayerAuthProvider>();
|
builder.Services.AddScoped<IAccessLayerAuthenticationProvider, BlazorAccessLayerAuthProvider>();
|
||||||
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"], fac.GetRequiredService<IAccessLayerAuthenticationProvider>()));
|
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"], fac.GetRequiredService<IAccessLayerAuthenticationProvider>(), fac.GetRequiredService<ILogger<WebApiAccessLayer>>()));
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddServerSideBlazor();
|
builder.Services.AddServerSideBlazor();
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
@@ -19,9 +20,14 @@ builder.Services.AddControllers().AddNewtonsoftJson(opt =>
|
|||||||
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
});
|
});
|
||||||
builder.Services.AddOIDCAuth(builder.Configuration);
|
builder.Services.AddOIDCAuth(builder.Configuration);
|
||||||
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders =
|
||||||
|
ForwardedHeaders.XForwardedHost | ForwardedHeaders.XForwardedProto;
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
app.UseForwardedHeaders();
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@@ -29,8 +35,12 @@ if (!app.Environment.IsDevelopment())
|
|||||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user