mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Ignore the UserName header as part of the Api is the value is an empty string
This commit is contained in:
parent
634928a3af
commit
1565ebce0d
1 changed files with 13 additions and 3 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue