mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 21:33:15 -07:00
This commit is contained in:
parent
0e6a1707f4
commit
9a2b0f6102
6 changed files with 69 additions and 58 deletions
|
@ -54,7 +54,6 @@ namespace Ombi.DependencyInjection
|
|||
services.RegisterApi();
|
||||
services.RegisterServices();
|
||||
services.RegisterStore();
|
||||
services.RegisterIdentity();
|
||||
services.RegisterJobs();
|
||||
}
|
||||
|
||||
|
@ -135,15 +134,5 @@ namespace Ombi.DependencyInjection
|
|||
services.AddTransient<IRadarrCacher, RadarrCacher>();
|
||||
services.AddTransient<IOmbiAutomaticUpdater, OmbiAutomaticUpdater>();
|
||||
}
|
||||
|
||||
public static void RegisterIdentity(this IServiceCollection services)
|
||||
{
|
||||
services.AddAuthorization(auth =>
|
||||
{
|
||||
auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
|
||||
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser().Build());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
VisualStudioVersion = 15.0.26730.15
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}"
|
||||
EndProject
|
||||
|
@ -10,7 +10,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
..\appveyor.yml = ..\appveyor.yml
|
||||
..\build.cake = ..\build.cake
|
||||
..\CHANGELOG.md = ..\CHANGELOG.md
|
||||
..\global.json = ..\global.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Core", "Ombi.Core\Ombi.Core.csproj", "{F56E79C7-791D-4668-A0EC-29E3BBC8D24B}"
|
||||
|
|
|
@ -77,6 +77,7 @@ namespace Ombi.Controllers
|
|||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_tokenAuthenticationOptions.SecretKey));
|
||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
|
||||
|
||||
var token = new JwtSecurityToken(
|
||||
claims: claims,
|
||||
expires: DateTime.UtcNow.AddHours(5),
|
||||
|
|
|
@ -90,7 +90,32 @@ namespace Ombi
|
|||
});
|
||||
|
||||
services.AddMemoryCache();
|
||||
|
||||
|
||||
var tokenOptions = Configuration.GetSection("TokenAuthentication");
|
||||
|
||||
var tokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenOptions.GetValue("SecretKey", string.Empty))),
|
||||
|
||||
RequireExpirationTime = true,
|
||||
ValidateLifetime = true,
|
||||
ValidAudience = "Ombi",
|
||||
ValidIssuer = "Ombi",
|
||||
ClockSkew = TimeSpan.Zero,
|
||||
};
|
||||
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
}).AddJwtBearer(x =>
|
||||
{
|
||||
x.Audience = "Ombi";
|
||||
x.TokenValidationParameters = tokenValidationParameters;
|
||||
});
|
||||
|
||||
services.AddMvc()
|
||||
.AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
|
||||
|
||||
|
@ -156,29 +181,8 @@ namespace Ombi
|
|||
});
|
||||
|
||||
|
||||
var tokenOptions = Configuration.GetSection("TokenAuthentication");
|
||||
|
||||
|
||||
|
||||
var tokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenOptions.GetValue("SecretKey", string.Empty))),
|
||||
|
||||
RequireExpirationTime = true,
|
||||
ValidateLifetime = true,
|
||||
ValidAudience = "Ombi",
|
||||
ValidIssuer = "Ombi",
|
||||
ClockSkew = TimeSpan.Zero
|
||||
};
|
||||
|
||||
services.AddAuthentication().AddJwtBearer(x =>
|
||||
{
|
||||
x.Audience = "Ombi";
|
||||
x.TokenValidationParameters = tokenValidationParameters;
|
||||
});
|
||||
|
||||
// Build the intermediate service provider
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
|
@ -195,17 +199,15 @@ namespace Ombi
|
|||
|
||||
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
loggerFactory.AddSerilog();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
|
||||
{
|
||||
HotModuleReplacement = true
|
||||
});
|
||||
//app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
|
||||
//{
|
||||
// HotModuleReplacement = true
|
||||
//});
|
||||
}
|
||||
|
||||
app.UseHangfireServer();
|
||||
|
@ -235,6 +237,10 @@ namespace Ombi
|
|||
ContentTypeProvider = provider
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue