Compare commits

..

No commits in common. "aeb2038b81a92a42ba34c19c907884ddf0f6beb8" and "f5b7ddd362549bb2c9012bc4f07552986e85524a" have entirely different histories.

7 changed files with 21 additions and 63 deletions

@ -1 +1 @@
Subproject commit c092b8a679c218c845e4981deb7b5b5dd174a311
Subproject commit 5341179e9421b7d8c4e54ce4962fc856cef4d6ed

View File

@ -1,40 +0,0 @@
using Blazored.LocalStorage;
using DotBased;
using DotBased.ASP.Auth;
using DotBased.Extensions;
using DotBased.Logging;
using Serilog;
using ILogger = DotBased.Logging.ILogger;
namespace SharpRSS.Blazor.Auth;
public class LocalStorageSessionStateProvider : ISessionStateProvider
{
public LocalStorageSessionStateProvider(ILocalStorageService localStorage)
{
_localStorage = localStorage;
_logger = LogService.RegisterLogger(typeof(LocalStorageSessionStateProvider));
}
private readonly ILocalStorageService _localStorage;
private readonly ILogger _logger;
public async Task<Result<string>> GetSessionStateAsync()
{
var localStorageValue = await _localStorage.GetItemAsync<string>(ISessionStateProvider.SessionStateName);
if (localStorageValue != null && !localStorageValue.IsNullOrWhiteSpace())
return Result<string>.Ok(localStorageValue);
_logger.Warning("Failed to get session token from local storage!");
return Result<string>.Failed("Local storage returned null or empty on session token.");
}
public async Task<Result> SetSessionStateAsync(string state)
{
if (state.IsNullOrWhiteSpace())
{
Log.Warning("Tried to save empty or null session state to local storage!");
return Result.Failed("Could not set session state to local storage, value is empty or null!");
}
await _localStorage.SetItemAsync(ISessionStateProvider.SessionStateName, state);
return Result.Ok();
}
}

View File

@ -1,35 +1,16 @@
using Blazored.LocalStorage;
using DotBased.ASP.Auth;
using DotBased.ASP.Auth.Domains.Auth;
using DotBased.ASP.Auth.Domains.Identity;
using Microsoft.EntityFrameworkCore;
using MudBlazor.Services;
using SharpRSS.Blazor.Auth;
using SharpRSS.Blazor.Components;
using SharpRSS.Business;
using SharpRSS.Data;
using SharpRSS.Data.Domains.Configuration;
var builder = WebApplication.CreateBuilder(args);
builder.AddSRSS();
builder.UseSRSS();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBasedServerAuth(options =>
{
options.AllowRegistration = false;
options.AuthenticationStateMaxAgeBeforeExpire = TimeSpan.FromDays(7);
options.LoginPath = "/auth/login";
options.LogoutPath = "/auth/logout";
options.SeedData = service =>
{
service.CreateUserAsync(new UserModel() { UserName = "Admin", Email = "admin@example.com", Enabled = true, PasswordHash = "password", Roles = new List<RoleModel>() { new RoleModel() { Name = "Admin", Description = "Administration role." }}});
service.CreateUserAsync(new UserModel() { UserName = "User", Email = "user@example.com", Enabled = true, PasswordHash = "password"});
};
options.SetDataProviderType<MemoryAuthDataProvider>();
options.SetSessionStateProviderType<LocalStorageSessionStateProvider>();
});
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
@ -75,7 +56,8 @@ if (!app.Environment.IsDevelopment())
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.UseBasedServerAuth();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

Binary file not shown.

View File

@ -31,4 +31,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Auth\" />
</ItemGroup>
</Project>

View File

@ -16,7 +16,7 @@ namespace SharpRSS.Business;
public static class DependencyInjection
{
public static WebApplicationBuilder AddSRSS(this WebApplicationBuilder builder)
public static WebApplicationBuilder UseSRSS(this WebApplicationBuilder builder)
{
/*
* Logging (serilog)
@ -64,6 +64,18 @@ public static class DependencyInjection
*/
builder.Services.AddScoped<AuthService>();
/*
* Authentication
*/
builder.Services.UseBasedAuth(options =>
{
options.AllowRegistration = false;
options.AuthenticationStateMaxAgeBeforeExpire = TimeSpan.FromDays(7);
options.LoginPath = "/auth/login";
options.LogoutPath = "/auth/logout";
});
builder.Services.AddCascadingAuthenticationState();
//TODO: Auth, Settings
return builder;
}