Teach swagger about IPCPassword

This commit is contained in:
JustArchi
2018-11-07 01:32:40 +01:00
parent f4425f0e71
commit 62dfcd8946
2 changed files with 19 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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" });