mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Add CORS (#930)
* Add CORS for users with set IPCPassword * Use newest preview Version of Microsoft.AspNetCore.Cors and Fix comments * Fix typo
This commit is contained in:
committed by
Łukasz Domeradzki
parent
68a365f95e
commit
d3474389f5
@@ -42,6 +42,7 @@
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.9" />
|
||||
<PackageReference Include="Humanizer" Version="2.5.1" />
|
||||
<PackageReference Include="Markdig.Signed" Version="0.15.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0-preview3-35497" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0-preview3-35497" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0-preview3-35497" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0-preview3-35497" />
|
||||
|
||||
@@ -58,6 +58,10 @@ namespace ArchiSteamFarm.IPC {
|
||||
if (!string.IsNullOrEmpty(Program.GlobalConfig.IPCPassword)) {
|
||||
// We need ApiAuthenticationMiddleware for IPCPassword
|
||||
app.UseWhen(context => context.Request.Path.StartsWithSegments("/Api", StringComparison.OrdinalIgnoreCase), appBuilder => appBuilder.UseMiddleware<ApiAuthenticationMiddleware>());
|
||||
|
||||
// We want to apply CORS policy in order to allow userscripts and other third-party integrations to communicate with ASF API
|
||||
// We apply CORS policy only with IPCPassword set as extra authentication measure
|
||||
app.UseCors();
|
||||
}
|
||||
|
||||
// We need WebSockets support for /Api/Log
|
||||
@@ -91,6 +95,17 @@ namespace ArchiSteamFarm.IPC {
|
||||
// Add support for response compression
|
||||
services.AddResponseCompression();
|
||||
|
||||
// Add CORS to allow userscripts and third-party apps
|
||||
services.AddCors(
|
||||
builder => {
|
||||
builder.AddDefaultPolicy(
|
||||
policyBuilder => {
|
||||
policyBuilder.AllowAnyOrigin();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// Add swagger documentation generation
|
||||
services.AddSwaggerGen(
|
||||
c => {
|
||||
|
||||
Reference in New Issue
Block a user