mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Removed old code
This commit is contained in:
parent
a1c5124269
commit
b56bc8c807
1 changed files with 0 additions and 45 deletions
|
@ -114,50 +114,5 @@ namespace Ombi
|
||||||
x.TokenValidationParameters = tokenValidationParameters;
|
x.TokenValidationParameters = tokenValidationParameters;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task ValidateUserAccessToken(IServiceProvider serviceProvider, HttpContext context, Func<Task> next, string key)
|
|
||||||
{
|
|
||||||
if (key.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
await context.Response.WriteAsync("Invalid User Access Token");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var um = serviceProvider.GetService<OmbiUserManager>();
|
|
||||||
var user = await um.Users.FirstOrDefaultAsync(x => x.UserAccessToken == key);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
||||||
await context.Response.WriteAsync("Invalid User Access Token");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
var identity = new GenericIdentity(user.UserName);
|
|
||||||
var roles = await um.GetRolesAsync(user);
|
|
||||||
var principal = new GenericPrincipal(identity, roles.ToArray());
|
|
||||||
context.User = principal;
|
|
||||||
await next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task ValidateApiKey(IServiceProvider serviceProvider, HttpContext context, Func<Task> next, string key)
|
|
||||||
{
|
|
||||||
var settingsProvider = serviceProvider.GetService<ISettingsService<OmbiSettings>>();
|
|
||||||
var ombiSettings = settingsProvider.GetSettings();
|
|
||||||
var valid = ombiSettings.ApiKey.Equals(key, StringComparison.CurrentCultureIgnoreCase);
|
|
||||||
if (!valid)
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
||||||
await context.Response.WriteAsync("Invalid API Key");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var identity = new GenericIdentity("API");
|
|
||||||
var principal = new GenericPrincipal(identity, new[] { "Admin", "ApiUser" });
|
|
||||||
context.User = principal;
|
|
||||||
await next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue