mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 10:36:54 -07:00
Merge branch 'develop' of https://github.com/tidusjar/ombi into develop
This commit is contained in:
commit
4f49bf0255
2 changed files with 12 additions and 11 deletions
|
@ -182,14 +182,16 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{@RECENTLYADDED}
|
||||
{@RECENTLYADDED}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- END MAIN CONTENT AREA -->
|
||||
</table>
|
||||
|
||||
<!-- START FOOTER -->
|
||||
<div class="footer" style="clear: both; padding-top: 10px; text-align: center; width: 100%;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
|
||||
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;">
|
||||
<tr>
|
||||
<td class="content-block powered-by" style="font-family: sans-serif; vertical-align: top; padding-top: 10px; padding-bottom: 10px; font-size: 12px; color: #999999; text-align: center;" valign="top" align="center">
|
||||
Powered by <a href="https://github.com/tidusjar/Ombi" style="color: #999999; font-size: 12px; text-align: center; text-decoration: underline;">Ombi</a>
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Security.Principal;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Settings.Settings.Models;
|
||||
|
@ -13,15 +14,11 @@ namespace Ombi
|
|||
{
|
||||
public class ApiKeyMiddlewear
|
||||
{
|
||||
public ApiKeyMiddlewear(RequestDelegate next, ISettingsService<OmbiSettings> repo, OmbiUserManager um)
|
||||
public ApiKeyMiddlewear(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
_repo = repo;
|
||||
_userManager = um;
|
||||
}
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ISettingsService<OmbiSettings> _repo;
|
||||
private readonly OmbiUserManager _userManager;
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
|
@ -66,8 +63,9 @@ namespace Ombi
|
|||
await context.Response.WriteAsync("Invalid User Access Token");
|
||||
return;
|
||||
}
|
||||
|
||||
var user = await _userManager.Users.FirstOrDefaultAsync(x => x.UserAccessToken == key);
|
||||
|
||||
var um = context.RequestServices.GetService<OmbiUserManager>();
|
||||
var user = await um.Users.FirstOrDefaultAsync(x => x.UserAccessToken == key);
|
||||
if (user == null)
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||
|
@ -77,7 +75,7 @@ namespace Ombi
|
|||
{
|
||||
|
||||
var identity = new GenericIdentity(user.UserName);
|
||||
var roles = await _userManager.GetRolesAsync(user);
|
||||
var roles = await um.GetRolesAsync(user);
|
||||
var principal = new GenericPrincipal(identity, roles.ToArray());
|
||||
context.User = principal;
|
||||
await next.Invoke(context);
|
||||
|
@ -86,7 +84,8 @@ namespace Ombi
|
|||
|
||||
private async Task ValidateApiKey(HttpContext context, RequestDelegate next, string key)
|
||||
{
|
||||
var ombiSettings = await _repo.GetSettingsAsync();
|
||||
var repo = context.RequestServices.GetService<ISettingsService<OmbiSettings>>();
|
||||
var ombiSettings = await repo.GetSettingsAsync();
|
||||
var valid = ombiSettings.ApiKey.Equals(key, StringComparison.CurrentCultureIgnoreCase);
|
||||
if (!valid)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue