🔀 Merge branch 'refactor/seprate-auth'
# Conflicts: # DysonNetwork.Sphere/Chat/Realtime/LiveKitService.cs # DysonNetwork.Sphere/Chat/RealtimeCallController.cs # DysonNetwork.Sphere/Startup/ServiceCollectionExtensions.cs # DysonNetwork.sln.DotSettings.user
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
using System.Net;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Sphere.Connection;
|
||||
using DysonNetwork.Sphere.Permission;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Prometheus;
|
||||
using tusdotnet;
|
||||
using tusdotnet.Stores;
|
||||
|
||||
namespace DysonNetwork.Sphere.Startup;
|
||||
|
||||
public static class ApplicationConfiguration
|
||||
{
|
||||
public static WebApplication ConfigureAppMiddleware(this WebApplication app, IConfiguration configuration, TusDiskStore tusDiskStore)
|
||||
public static WebApplication ConfigureAppMiddleware(this WebApplication app, IConfiguration configuration)
|
||||
{
|
||||
app.MapMetrics();
|
||||
app.MapOpenApi();
|
||||
app.UseMiddleware<ClientTypeMiddleware>();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
@@ -24,27 +20,15 @@ public static class ApplicationConfiguration
|
||||
|
||||
ConfigureForwardedHeaders(app, configuration);
|
||||
|
||||
app.UseCors(opts =>
|
||||
opts.SetIsOriginAllowed(_ => true)
|
||||
.WithExposedHeaders("*")
|
||||
.WithHeaders()
|
||||
.AllowCredentials()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
);
|
||||
|
||||
app.UseWebSockets();
|
||||
app.UseRateLimiter();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseMiddleware<PermissionMiddleware>();
|
||||
|
||||
app.MapControllers().RequireRateLimiting("fixed");
|
||||
app.MapStaticAssets().RequireRateLimiting("fixed");
|
||||
app.MapRazorPages().RequireRateLimiting("fixed");
|
||||
app.MapControllers();
|
||||
|
||||
app.MapTus("/files/tus", _ => Task.FromResult(TusService.BuildConfiguration(tusDiskStore)));
|
||||
// Map gRPC services
|
||||
app.MapGrpcService<WebSocketHandlerGrpc>();
|
||||
|
||||
return app;
|
||||
}
|
||||
|
@@ -1,7 +1,4 @@
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using DysonNetwork.Sphere.Connection.WebReader;
|
||||
using DysonNetwork.Sphere.Storage.Handlers;
|
||||
using DysonNetwork.Sphere.Wallet;
|
||||
using DysonNetwork.Sphere.WebReader;
|
||||
using Quartz;
|
||||
|
||||
namespace DysonNetwork.Sphere.Startup;
|
||||
@@ -19,63 +16,15 @@ public static class ScheduledJobsConfiguration
|
||||
.WithIdentity("AppDatabaseRecyclingTrigger")
|
||||
.WithCronSchedule("0 0 0 * * ?"));
|
||||
|
||||
var cloudFilesRecyclingJob = new JobKey("CloudFilesUnusedRecycling");
|
||||
q.AddJob<CloudFileUnusedRecyclingJob>(opts => opts.WithIdentity(cloudFilesRecyclingJob));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(cloudFilesRecyclingJob)
|
||||
.WithIdentity("CloudFilesUnusedRecyclingTrigger")
|
||||
.WithSimpleSchedule(o => o.WithIntervalInHours(1).RepeatForever())
|
||||
);
|
||||
|
||||
var actionLogFlushJob = new JobKey("ActionLogFlush");
|
||||
q.AddJob<ActionLogFlushJob>(opts => opts.WithIdentity(actionLogFlushJob));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(actionLogFlushJob)
|
||||
.WithIdentity("ActionLogFlushTrigger")
|
||||
.WithSimpleSchedule(o => o
|
||||
.WithIntervalInMinutes(5)
|
||||
.RepeatForever())
|
||||
);
|
||||
|
||||
var readReceiptFlushJob = new JobKey("ReadReceiptFlush");
|
||||
q.AddJob<ReadReceiptFlushJob>(opts => opts.WithIdentity(readReceiptFlushJob));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(readReceiptFlushJob)
|
||||
.WithIdentity("ReadReceiptFlushTrigger")
|
||||
.WithSimpleSchedule(o => o
|
||||
.WithIntervalInSeconds(60)
|
||||
.RepeatForever())
|
||||
);
|
||||
|
||||
var lastActiveFlushJob = new JobKey("LastActiveFlush");
|
||||
q.AddJob<LastActiveFlushJob>(opts => opts.WithIdentity(lastActiveFlushJob));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(lastActiveFlushJob)
|
||||
.WithIdentity("LastActiveFlushTrigger")
|
||||
.WithSimpleSchedule(o => o
|
||||
.WithIntervalInMinutes(5)
|
||||
.RepeatForever())
|
||||
);
|
||||
|
||||
var postViewFlushJob = new JobKey("PostViewFlush");
|
||||
q.AddJob<PostViewFlushJob>(opts => opts.WithIdentity(postViewFlushJob));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(postViewFlushJob)
|
||||
.WithIdentity("PostViewFlushTrigger")
|
||||
.WithSimpleSchedule(o => o
|
||||
.WithIntervalInMinutes(1)
|
||||
.RepeatForever())
|
||||
);
|
||||
|
||||
var subscriptionRenewalJob = new JobKey("SubscriptionRenewal");
|
||||
q.AddJob<SubscriptionRenewalJob>(opts => opts.WithIdentity(subscriptionRenewalJob));
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(subscriptionRenewalJob)
|
||||
.WithIdentity("SubscriptionRenewalTrigger")
|
||||
.WithSimpleSchedule(o => o
|
||||
.WithIntervalInMinutes(30)
|
||||
.RepeatForever())
|
||||
);
|
||||
// var postViewFlushJob = new JobKey("PostViewFlush");
|
||||
// q.AddJob<PostViewFlushJob>(opts => opts.WithIdentity(postViewFlushJob));
|
||||
// q.AddTrigger(opts => opts
|
||||
// .ForJob(postViewFlushJob)
|
||||
// .WithIdentity("PostViewFlushTrigger")
|
||||
// .WithSimpleSchedule(o => o
|
||||
// .WithIntervalInMinutes(1)
|
||||
// .RepeatForever())
|
||||
// );
|
||||
|
||||
var webFeedScraperJob = new JobKey("WebFeedScraper");
|
||||
q.AddJob<WebFeedScraperJob>(opts => opts.WithIdentity(webFeedScraperJob));
|
||||
|
@@ -1,22 +1,12 @@
|
||||
using System.Globalization;
|
||||
using DysonNetwork.Sphere.Account;
|
||||
using DysonNetwork.Sphere.Activity;
|
||||
using DysonNetwork.Sphere.Auth;
|
||||
using DysonNetwork.Sphere.Auth.OpenId;
|
||||
using DysonNetwork.Sphere.Chat;
|
||||
using DysonNetwork.Sphere.Chat.Realtime;
|
||||
using DysonNetwork.Sphere.Connection;
|
||||
using DysonNetwork.Sphere.Connection.Handlers;
|
||||
using DysonNetwork.Sphere.Email;
|
||||
using DysonNetwork.Sphere.Localization;
|
||||
using DysonNetwork.Sphere.Permission;
|
||||
using DysonNetwork.Sphere.Post;
|
||||
using DysonNetwork.Sphere.Publisher;
|
||||
using DysonNetwork.Sphere.Realm;
|
||||
using DysonNetwork.Sphere.Sticker;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using DysonNetwork.Sphere.Storage.Handlers;
|
||||
using DysonNetwork.Sphere.Wallet;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using NodaTime;
|
||||
@@ -24,14 +14,12 @@ using NodaTime.Serialization.SystemTextJson;
|
||||
using StackExchange.Redis;
|
||||
using System.Text.Json;
|
||||
using System.Threading.RateLimiting;
|
||||
using DysonNetwork.Sphere.Auth.OidcProvider.Options;
|
||||
using DysonNetwork.Sphere.Auth.OidcProvider.Services;
|
||||
using DysonNetwork.Sphere.Connection.WebReader;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.GeoIp;
|
||||
using DysonNetwork.Sphere.WebReader;
|
||||
using DysonNetwork.Sphere.Developer;
|
||||
using DysonNetwork.Sphere.Discovery;
|
||||
using DysonNetwork.Sphere.Safety;
|
||||
using DysonNetwork.Sphere.Wallet.PaymentHandlers;
|
||||
using tusdotnet.Stores;
|
||||
|
||||
namespace DysonNetwork.Sphere.Startup;
|
||||
|
||||
@@ -53,20 +41,6 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
services.AddHttpClient();
|
||||
|
||||
// Register OIDC services
|
||||
services.AddScoped<OidcService, GoogleOidcService>();
|
||||
services.AddScoped<OidcService, AppleOidcService>();
|
||||
services.AddScoped<OidcService, GitHubOidcService>();
|
||||
services.AddScoped<OidcService, MicrosoftOidcService>();
|
||||
services.AddScoped<OidcService, DiscordOidcService>();
|
||||
services.AddScoped<OidcService, AfdianOidcService>();
|
||||
services.AddScoped<GoogleOidcService>();
|
||||
services.AddScoped<AppleOidcService>();
|
||||
services.AddScoped<GitHubOidcService>();
|
||||
services.AddScoped<MicrosoftOidcService>();
|
||||
services.AddScoped<DiscordOidcService>();
|
||||
services.AddScoped<AfdianOidcService>();
|
||||
|
||||
services.AddControllers().AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
|
||||
@@ -79,6 +53,11 @@ public static class ServiceCollectionExtensions
|
||||
factory.Create(typeof(SharedResource));
|
||||
});
|
||||
services.AddRazorPages();
|
||||
|
||||
services.AddGrpc(options =>
|
||||
{
|
||||
options.EnableDetailedErrors = true;
|
||||
});
|
||||
|
||||
services.Configure<RequestLocalizationOptions>(options =>
|
||||
{
|
||||
@@ -112,12 +91,6 @@ public static class ServiceCollectionExtensions
|
||||
{
|
||||
services.AddCors();
|
||||
services.AddAuthorization();
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = AuthConstants.SchemeName;
|
||||
options.DefaultChallengeScheme = AuthConstants.SchemeName;
|
||||
})
|
||||
.AddScheme<DysonTokenAuthOptions, DysonTokenAuthHandler>(AuthConstants.SchemeName, _ => { });
|
||||
|
||||
return services;
|
||||
}
|
||||
@@ -168,30 +141,9 @@ public static class ServiceCollectionExtensions
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddAppFileStorage(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var tusStorePath = configuration.GetSection("Tus").GetValue<string>("StorePath")!;
|
||||
Directory.CreateDirectory(tusStorePath);
|
||||
var tusDiskStore = new TusDiskStore(tusStorePath);
|
||||
|
||||
services.AddSingleton(tusDiskStore);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddAppFlushHandlers(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FlushBufferService>();
|
||||
services.AddScoped<ActionLogFlushHandler>();
|
||||
services.AddScoped<MessageReadReceiptFlushHandler>();
|
||||
services.AddScoped<LastActiveFlushHandler>();
|
||||
services.AddScoped<PostViewFlushHandler>();
|
||||
|
||||
// The handlers for websocket
|
||||
services.AddScoped<IWebSocketPacketHandler, MessageReadHandler>();
|
||||
services.AddScoped<IWebSocketPacketHandler, MessageTypingHandler>();
|
||||
services.AddScoped<IWebSocketPacketHandler, MessagesSubscribeHandler>();
|
||||
services.AddScoped<IWebSocketPacketHandler, MessagesUnsubscribeHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
@@ -199,25 +151,8 @@ public static class ServiceCollectionExtensions
|
||||
public static IServiceCollection AddAppBusinessServices(this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddScoped<CompactTokenService>();
|
||||
services.AddScoped<RazorViewRenderer>();
|
||||
services.Configure<GeoIpOptions>(configuration.GetSection("GeoIP"));
|
||||
services.AddScoped<GeoIpService>();
|
||||
services.AddScoped<WebSocketService>();
|
||||
services.AddScoped<EmailService>();
|
||||
services.AddScoped<PermissionService>();
|
||||
services.AddScoped<ActionLogService>();
|
||||
services.AddScoped<AccountService>();
|
||||
services.AddScoped<AccountEventService>();
|
||||
services.AddScoped<ActionLogService>();
|
||||
services.AddScoped<RelationshipService>();
|
||||
services.AddScoped<MagicSpellService>();
|
||||
services.AddScoped<NotificationService>();
|
||||
services.AddScoped<AuthService>();
|
||||
services.AddScoped<AccountUsernameService>();
|
||||
services.AddScoped<FileService>();
|
||||
services.AddScoped<FileReferenceService>();
|
||||
services.AddScoped<FileReferenceMigrationService>();
|
||||
services.AddScoped<PublisherService>();
|
||||
services.AddScoped<PublisherSubscriptionService>();
|
||||
services.AddScoped<ActivityService>();
|
||||
@@ -229,12 +164,9 @@ public static class ServiceCollectionExtensions
|
||||
services.AddScoped<WalletService>();
|
||||
services.AddScoped<SubscriptionService>();
|
||||
services.AddScoped<PaymentService>();
|
||||
services.AddScoped<RealtimeStatusService>();
|
||||
services.AddRealtimeService(configuration);
|
||||
services.AddScoped<IRealtimeService, LivekitRealtimeService>();
|
||||
services.AddScoped<WebReaderService>();
|
||||
services.AddScoped<WebFeedService>();
|
||||
services.AddScoped<AfdianPaymentHandler>();
|
||||
services.AddScoped<SafetyService>();
|
||||
services.AddScoped<DiscoveryService>();
|
||||
services.AddScoped<CustomAppService>();
|
||||
|
||||
@@ -243,22 +175,4 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IServiceCollection AddRealtimeService(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var provider = configuration["Realtime:Provider"];
|
||||
switch (provider)
|
||||
{
|
||||
case "Cloudflare":
|
||||
services.AddHttpClient<IRealtimeService, CloudflareRealtimeService>();
|
||||
break;
|
||||
case "LiveKit":
|
||||
services.AddScoped<IRealtimeService, LiveKitRealtimeService>();
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException($"Realtime provider '{provider}' is not supported.");
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user