mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Teach swagger about IPCPassword
This commit is contained in:
@@ -32,6 +32,8 @@ using Microsoft.Extensions.Primitives;
|
||||
namespace ArchiSteamFarm.IPC.Middleware {
|
||||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
|
||||
internal sealed class ApiAuthenticationMiddleware {
|
||||
internal const string HeadersField = "Authentication";
|
||||
|
||||
private const byte FailedAuthorizationsCooldownInHours = 1;
|
||||
private const byte MaxFailedAuthorizationAttempts = 5;
|
||||
|
||||
@@ -86,7 +88,7 @@ namespace ArchiSteamFarm.IPC.Middleware {
|
||||
}
|
||||
}
|
||||
|
||||
if (!context.Request.Headers.TryGetValue("Authentication", out StringValues passwords) && !context.Request.Query.TryGetValue("password", out passwords)) {
|
||||
if (!context.Request.Headers.TryGetValue(HeadersField, out StringValues passwords) && !context.Request.Query.TryGetValue("password", out passwords)) {
|
||||
return HttpStatusCode.Unauthorized;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ArchiSteamFarm.IPC.Middleware;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@@ -101,6 +102,21 @@ namespace ArchiSteamFarm.IPC {
|
||||
// Add swagger documentation generation
|
||||
services.AddSwaggerGen(
|
||||
c => {
|
||||
c.AddSecurityDefinition(
|
||||
nameof(GlobalConfig.IPCPassword), new ApiKeyScheme {
|
||||
Description = "IPCPassword authentication using request headers. Check https://github.com/JustArchiNET/ArchiSteamFarm/wiki/IPC#authentication for more info.",
|
||||
In = "header",
|
||||
Name = ApiAuthenticationMiddleware.HeadersField,
|
||||
Type = "apiKey"
|
||||
}
|
||||
);
|
||||
|
||||
c.AddSecurityRequirement(
|
||||
new Dictionary<string, IEnumerable<string>> {
|
||||
{ nameof(GlobalConfig.IPCPassword), new string[0] }
|
||||
}
|
||||
);
|
||||
|
||||
c.DescribeAllEnumsAsStrings();
|
||||
c.EnableAnnotations();
|
||||
c.SwaggerDoc("ASF", new Info { Title = "ASF API" });
|
||||
|
||||
Reference in New Issue
Block a user