mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
Upgrade to ASP.NET Core RC2 release.
This commit is contained in:
@ -1,14 +1,15 @@
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authentication.JwtBearer;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Domains;
|
||||
@ -16,7 +17,8 @@ using Bit.Core.Identity;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Repos = Bit.Core.Repositories.SqlServer;
|
||||
using Loggr.Extensions.Logging;
|
||||
using System.Text;
|
||||
//using Loggr.Extensions.Logging;
|
||||
|
||||
namespace Bit.Api
|
||||
{
|
||||
@ -25,6 +27,7 @@ namespace Bit.Api
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("settings.json")
|
||||
.AddJsonFile($"settings.{env.EnvironmentName}.json", optional: true);
|
||||
|
||||
@ -42,14 +45,14 @@ namespace Bit.Api
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<GlobalSettings>(Configuration.GetSection("globalSettings"));
|
||||
var provider = services.BuildServiceProvider();
|
||||
|
||||
// Options
|
||||
services.AddOptions();
|
||||
|
||||
// Settings
|
||||
var provider = services.BuildServiceProvider();
|
||||
var globalSettings = provider.GetRequiredService<IOptions<GlobalSettings>>().Value;
|
||||
var globalSettings = new GlobalSettings();
|
||||
ConfigurationBinder.Bind(Configuration.GetSection("GlobalSettings"), globalSettings);
|
||||
services.AddSingleton(s => globalSettings);
|
||||
|
||||
// Repositories
|
||||
@ -75,7 +78,7 @@ namespace Bit.Api
|
||||
RequireDigit = false,
|
||||
RequireLowercase = false,
|
||||
RequiredLength = 8,
|
||||
RequireNonLetterOrDigit = false,
|
||||
RequireNonAlphanumeric = false,
|
||||
RequireUppercase = false
|
||||
};
|
||||
options.ClaimsIdentity = new ClaimsIdentityOptions
|
||||
@ -90,9 +93,8 @@ namespace Bit.Api
|
||||
jwtBearerOptions.Issuer = "bitwarden";
|
||||
jwtBearerOptions.TokenLifetime = TimeSpan.FromDays(10 * 365);
|
||||
jwtBearerOptions.TwoFactorTokenLifetime = TimeSpan.FromMinutes(10);
|
||||
// TODO: Symmetric key
|
||||
// waiting on https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/250
|
||||
jwtBearerOptions.SigningCredentials = null;
|
||||
var keyBytes = Encoding.ASCII.GetBytes(globalSettings.JwtSigningKey);
|
||||
jwtBearerOptions.SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(keyBytes), SecurityAlgorithms.HmacSha256);
|
||||
})
|
||||
.AddUserStore<UserStore>()
|
||||
.AddRoleStore<RoleStore>()
|
||||
@ -138,21 +140,17 @@ namespace Bit.Api
|
||||
ILoggerFactory loggerFactory,
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
loggerFactory.MinimumLevel = LogLevel.Information;
|
||||
loggerFactory.AddConsole();
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
if(!env.IsDevelopment())
|
||||
{
|
||||
loggerFactory.AddLoggr(
|
||||
LogLevel.Error,
|
||||
globalSettings.Loggr.LogKey,
|
||||
globalSettings.Loggr.ApiKey);
|
||||
//loggerFactory.AddLoggr(
|
||||
// LogLevel.Error,
|
||||
// globalSettings.Loggr.LogKey,
|
||||
// globalSettings.Loggr.ApiKey);
|
||||
}
|
||||
|
||||
// Add the platform handler to the request pipeline.
|
||||
app.UseIISPlatformHandler();
|
||||
|
||||
// Add static files to the request pipeline.
|
||||
app.UseStaticFiles();
|
||||
|
||||
@ -165,8 +163,5 @@ namespace Bit.Api
|
||||
// Add MVC to the request pipeline.
|
||||
app.UseMvc();
|
||||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user