Skip to content
Merged

Beta #112

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions EasyFortniteStats-ImageApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="7.1.6" />
<PackageReference Include="SkiaSharp" Version="3.119.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
<PackageReference Include="AsyncKeyedLock" Version="7.1.7" />
<PackageReference Include="SkiaSharp" Version="3.119.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
</ItemGroup>

<!-- Include asset files -->
Expand Down
34 changes: 34 additions & 0 deletions Middleware/ApiKeyAuthenticationMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace EasyFortniteStats_ImageApi.Middleware;

public class ApiKeyAuthenticationMiddleware(RequestDelegate next, IConfiguration configuration)
{
private readonly string? _apiKey = configuration["API_KEY"] ?? Environment.GetEnvironmentVariable("API_KEY");

public async Task InvokeAsync(HttpContext context)
{
// If no API key is configured, skip authentication
if (string.IsNullOrEmpty(_apiKey))
{
await next(context);
return;
}

// Check if Authorization header is present
if (!context.Request.Headers.TryGetValue("Authorization", out var extractedApiKey))
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync("API Key is missing");
return;
}

// Validate the API key
if (!_apiKey.Equals(extractedApiKey))
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync("Unauthorized client");
return;
}

await next(context);
}
}
4 changes: 4 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AsyncKeyedLock;
using EasyFortniteStats_ImageApi;
using EasyFortniteStats_ImageApi.Middleware;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -18,6 +19,9 @@

var app = builder.Build();

// Add API Key authentication middleware
app.UseMiddleware<ApiKeyAuthenticationMiddleware>();

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# EasyFortniteStats ImageAPI

This is the internal API written in C# to generate the images for the [EasyFortniteStats Discord Bot](https://easyfnstats.com).

## Usage
This api isn't intended to be used in any other Discord related projects. Also commercial use is not allowed. This project can be used in following cases:

This api isn't intended to be used in any other Discord related projects. Also commercial use is not allowed. This project can be used in following cases:

- Private non-commercial use
- Public non-commercial projects (with credit)
- Educational use
- Open source projects (with credit)
- Open source projects (with credit)