mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
upgrade to aspnet core 3.1
This commit is contained in:
@ -2,11 +2,10 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.33.0</Version>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<RootNamespace>Bit.Api</RootNamespace>
|
||||
<UserSecretsId>bitwarden-Api</UserSecretsId>
|
||||
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
<ANCMPreConfiguredForIIS>true</ANCMPreConfiguredForIIS>
|
||||
</PropertyGroup>
|
||||
@ -24,7 +23,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
|
||||
|
||||
LABEL com.bitwarden.product="bitwarden"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Bit.Core.Utilities;
|
||||
using Serilog.Events;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@ -11,32 +11,37 @@ namespace Bit.Api
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
WebHost
|
||||
Host
|
||||
.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureLogging((hostingContext, logging) =>
|
||||
logging.AddSerilog(hostingContext, e =>
|
||||
{
|
||||
var context = e.Properties["SourceContext"].ToString();
|
||||
if(e.Exception != null && (e.Exception.GetType() == typeof(SecurityTokenValidationException) ||
|
||||
e.Exception.Message == "Bad security stamp."))
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
webBuilder.ConfigureLogging((hostingContext, logging) =>
|
||||
logging.AddSerilog(hostingContext, e =>
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var context = e.Properties["SourceContext"].ToString();
|
||||
if(e.Exception != null &&
|
||||
(e.Exception.GetType() == typeof(SecurityTokenValidationException) ||
|
||||
e.Exception.Message == "Bad security stamp."))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(e.Level == LogEventLevel.Information && context.Contains(typeof(IpRateLimitMiddleware).FullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(e.Level == LogEventLevel.Information &&
|
||||
context.Contains(typeof(IpRateLimitMiddleware).FullName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||
|
||||
context.Contains("IdentityServer4.Validation.TokenRequestValidator"))
|
||||
{
|
||||
return e.Level > LogEventLevel.Error;
|
||||
}
|
||||
if(context.Contains("IdentityServer4.Validation.TokenValidator") ||
|
||||
context.Contains("IdentityServer4.Validation.TokenRequestValidator"))
|
||||
{
|
||||
return e.Level > LogEventLevel.Error;
|
||||
}
|
||||
|
||||
return e.Level >= LogEventLevel.Error;
|
||||
}))
|
||||
return e.Level >= LogEventLevel.Error;
|
||||
}));
|
||||
})
|
||||
.Build()
|
||||
.Run();
|
||||
}
|
||||
|
@ -13,12 +13,13 @@ using Bit.Core.Utilities;
|
||||
using IdentityModel;
|
||||
using System.Globalization;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Bit.Api
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env, IConfiguration configuration)
|
||||
public Startup(IWebHostEnvironment env, IConfiguration configuration)
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
||||
Configuration = configuration;
|
||||
@ -26,7 +27,7 @@ namespace Bit.Api
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; private set; }
|
||||
public IHostingEnvironment Environment { get; set; }
|
||||
public IWebHostEnvironment Environment { get; set; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
@ -113,7 +114,7 @@ namespace Bit.Api
|
||||
{
|
||||
config.Conventions.Add(new ApiExplorerGroupConvention());
|
||||
config.Conventions.Add(new PublicApiControllersModelConvention());
|
||||
}).AddJsonOptions(options =>
|
||||
}).AddNewtonsoftJson(options =>
|
||||
{
|
||||
if(Environment.IsProduction() && Configuration["swaggerGen"] != "true")
|
||||
{
|
||||
@ -121,7 +122,7 @@ namespace Bit.Api
|
||||
}
|
||||
});
|
||||
|
||||
services.AddSwagger(globalSettings);
|
||||
//services.AddSwagger(globalSettings);
|
||||
|
||||
if(globalSettings.SelfHosted)
|
||||
{
|
||||
@ -138,8 +139,8 @@ namespace Bit.Api
|
||||
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IHostingEnvironment env,
|
||||
IApplicationLifetime appLifetime,
|
||||
IWebHostEnvironment env,
|
||||
IHostApplicationLifetime appLifetime,
|
||||
GlobalSettings globalSettings,
|
||||
ILogger<Startup> logger)
|
||||
{
|
||||
@ -162,39 +163,43 @@ namespace Bit.Api
|
||||
// Add static files to the request pipeline.
|
||||
app.UseStaticFiles();
|
||||
|
||||
// Add routing
|
||||
app.UseRouting();
|
||||
|
||||
// Add Cors
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(h => true)
|
||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||
|
||||
// Add authentication to the request pipeline.
|
||||
// Add authentication and authorization to the request pipeline.
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Add current context
|
||||
app.UseMiddleware<CurrentContextMiddleware>();
|
||||
|
||||
// Add MVC to the request pipeline.
|
||||
app.UseMvc();
|
||||
// Add endpoints to the request pipeline.
|
||||
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
||||
|
||||
// Add Swagger
|
||||
if(Environment.IsDevelopment() || globalSettings.SelfHosted)
|
||||
{
|
||||
app.UseSwagger(config =>
|
||||
{
|
||||
config.RouteTemplate = "specs/{documentName}/swagger.json";
|
||||
var host = globalSettings.BaseServiceUri.Api.Replace("https://", string.Empty)
|
||||
.Replace("http://", string.Empty);
|
||||
config.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = host);
|
||||
});
|
||||
app.UseSwaggerUI(config =>
|
||||
{
|
||||
config.DocumentTitle = "Bitwarden API Documentation";
|
||||
config.RoutePrefix = "docs";
|
||||
config.SwaggerEndpoint($"{globalSettings.BaseServiceUri.Api}/specs/public/swagger.json",
|
||||
"Bitwarden Public API");
|
||||
config.OAuthClientId("accountType.id");
|
||||
config.OAuthClientSecret("secretKey");
|
||||
});
|
||||
}
|
||||
//if(Environment.IsDevelopment() || globalSettings.SelfHosted)
|
||||
//{
|
||||
// app.UseSwagger(config =>
|
||||
// {
|
||||
// config.RouteTemplate = "specs/{documentName}/swagger.json";
|
||||
// var host = globalSettings.BaseServiceUri.Api.Replace("https://", string.Empty)
|
||||
// .Replace("http://", string.Empty);
|
||||
// config.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Host = host);
|
||||
// });
|
||||
// app.UseSwaggerUI(config =>
|
||||
// {
|
||||
// config.DocumentTitle = "Bitwarden API Documentation";
|
||||
// config.RoutePrefix = "docs";
|
||||
// config.SwaggerEndpoint($"{globalSettings.BaseServiceUri.Api}/specs/public/swagger.json",
|
||||
// "Bitwarden Public API");
|
||||
// config.OAuthClientId("accountType.id");
|
||||
// config.OAuthClientSecret("secretKey");
|
||||
// });
|
||||
//}
|
||||
|
||||
// Log startup
|
||||
logger.LogInformation(Constants.BypassFiltersEventId, globalSettings.ProjectName + " started.");
|
||||
|
Reference in New Issue
Block a user