mirror of
https://github.com/morbalint/kemkas-backend.git
synced 2026-07-17 21:23:46 +00:00
initial
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace Kemkas.Web.Config;
|
||||
|
||||
public class ExternalAuthOptions
|
||||
{
|
||||
public string? ClientId { get; set; }
|
||||
|
||||
public string? ClientSecret { get; set; }
|
||||
|
||||
public bool IsValid() => ClientId != null && ClientSecret != null;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Kemkas.Web.Config;
|
||||
|
||||
public class MailgunOptions
|
||||
{
|
||||
public const string Section = "Email";
|
||||
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
public string DomainName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace Kemkas.Web.Config;
|
||||
|
||||
public static class WebApplicationBuilderExtensions
|
||||
{
|
||||
public static void AddAuth(this WebApplicationBuilder builder)
|
||||
{
|
||||
var externalAuthConfigSection = builder.Configuration.GetSection("Authentication");
|
||||
var authenticationBuilder = builder.Services.AddAuthentication();
|
||||
|
||||
var googleAuthOptions = new ExternalAuthOptions();
|
||||
externalAuthConfigSection.GetSection("Google").Bind(googleAuthOptions);
|
||||
if (googleAuthOptions.IsValid())
|
||||
{
|
||||
authenticationBuilder.AddGoogle(options =>
|
||||
{
|
||||
options.ClientId = googleAuthOptions.ClientId!;
|
||||
options.ClientSecret = googleAuthOptions.ClientSecret!;
|
||||
});
|
||||
}
|
||||
|
||||
var facebookAuthOptions = new ExternalAuthOptions();
|
||||
externalAuthConfigSection.GetSection("Facebook").Bind(facebookAuthOptions);
|
||||
if (facebookAuthOptions.IsValid())
|
||||
{
|
||||
authenticationBuilder.AddFacebook(options =>
|
||||
{
|
||||
options.ClientId = facebookAuthOptions.ClientId!;
|
||||
options.ClientSecret = facebookAuthOptions.ClientSecret!;
|
||||
});
|
||||
}
|
||||
|
||||
var discordAuthOptions = new ExternalAuthOptions();
|
||||
externalAuthConfigSection.GetSection("Discord").Bind(discordAuthOptions);
|
||||
if (discordAuthOptions.IsValid())
|
||||
{
|
||||
authenticationBuilder.AddDiscord(options =>
|
||||
{
|
||||
options.ClientId = discordAuthOptions.ClientId!;
|
||||
options.ClientSecret = discordAuthOptions.ClientSecret!;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddOpenTelemetry(this WebApplicationBuilder builder)
|
||||
{
|
||||
var otlResourceBuilder = ResourceBuilder.CreateDefault().AddService("kemkas-api");
|
||||
var openTelemetryEndpoint = builder.Configuration.GetSection("monitoring")["url"];
|
||||
var consoleEnabled = builder.Configuration.GetSection("monitoring")["console"] == "true";
|
||||
|
||||
builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
|
||||
{
|
||||
tracerProviderBuilder
|
||||
.SetResourceBuilder(otlResourceBuilder)
|
||||
.AddAspNetCoreInstrumentation();
|
||||
if (openTelemetryEndpoint != null)
|
||||
{
|
||||
tracerProviderBuilder.AddOtlpExporter(opt => opt.Endpoint = new Uri(openTelemetryEndpoint));
|
||||
}
|
||||
else if (consoleEnabled)
|
||||
{
|
||||
tracerProviderBuilder.AddConsoleExporter();
|
||||
}
|
||||
})
|
||||
.WithMetrics(meterProviderBuilder =>
|
||||
{
|
||||
meterProviderBuilder
|
||||
.SetResourceBuilder(otlResourceBuilder)
|
||||
.AddAspNetCoreInstrumentation();
|
||||
if (openTelemetryEndpoint != null)
|
||||
{
|
||||
meterProviderBuilder.AddOtlpExporter(opt => opt.Endpoint = new Uri(openTelemetryEndpoint));
|
||||
}
|
||||
else if (consoleEnabled)
|
||||
{
|
||||
meterProviderBuilder.AddConsoleExporter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user