Ignore the UserName header as part of the Api is the value is an empty string

pull/2814/head
tidusjar 6 years ago
parent 634928a3af
commit 1565ebce0d

@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Ombi.Core.Authentication;
using Ombi.Core.Settings;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
namespace Ombi
@ -98,6 +99,10 @@ namespace Ombi
if (context.Request.Headers.Keys.Contains("UserName", StringComparer.InvariantCultureIgnoreCase))
{
var username = context.Request.Headers["UserName"].FirstOrDefault();
if (username.IsNullOrEmpty())
{
UseApiUser(context);
}
var um = context.RequestServices.GetService<OmbiUserManager>();
var user = await um.Users.FirstOrDefaultAsync(x =>
x.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase));
@ -114,13 +119,18 @@ namespace Ombi
}
else
{
var identity = new GenericIdentity("API");
var principal = new GenericPrincipal(identity, new[] { "Admin", "ApiUser" });
context.User = principal;
UseApiUser(context);
}
await next.Invoke(context);
}
}
private void UseApiUser(HttpContext context)
{
var identity = new GenericIdentity("API");
var principal = new GenericPrincipal(identity, new[] { "Admin", "ApiUser" });
context.User = principal;
}
}
}
Loading…
Cancel
Save