Migrated to latest libs and .net core 3.1 fingers crossed...
This commit is contained in:
50
Program.cs
50
Program.cs
@@ -1,5 +1,11 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace rockfishCore
|
||||
{
|
||||
@@ -7,17 +13,45 @@ namespace rockfishCore
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseUrls("http://*:3001")
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>()
|
||||
.UseUrls("http://*:3001")
|
||||
.CaptureStartupErrors(true)
|
||||
.UseSetting("detailedErrors", "true")
|
||||
.UseKestrel()
|
||||
.UseContentRoot(System.IO.Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
.UseContentRoot(System.IO.Directory.GetCurrentDirectory());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// namespace rockfishCore
|
||||
// {
|
||||
// public class Program
|
||||
// {
|
||||
// public static void Main(string[] args)
|
||||
// {
|
||||
// BuildWebHost(args).Run();
|
||||
// }
|
||||
|
||||
// public static IWebHost BuildWebHost(string[] args) =>
|
||||
// WebHost.CreateDefaultBuilder(args)
|
||||
// .UseUrls("http://*:3001")
|
||||
// .CaptureStartupErrors(true)
|
||||
// .UseSetting("detailedErrors", "true")
|
||||
// .UseKestrel()
|
||||
// .UseContentRoot(System.IO.Directory.GetCurrentDirectory())
|
||||
// .UseStartup<Startup>()
|
||||
// .Build();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
257
Startup.cs
257
Startup.cs
@@ -4,92 +4,90 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
//manually added
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using rockfishCore.Models;
|
||||
using rockfishCore.Util;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using rockfishCore.Util;
|
||||
|
||||
//added when upgrade to v2 of .netcore
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
//this comment added in windows with notepad++
|
||||
//this comment added in Linux with vscode
|
||||
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace rockfishCore
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
.AddEnvironmentVariables();
|
||||
Configuration = builder.Build();
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
services.AddDbContext<rockfishContext>(options =>
|
||||
{
|
||||
options.UseSqlite(Configuration.GetConnectionString("rfdb")).EnableSensitiveDataLogging(false);
|
||||
|
||||
services.AddDbContext<rockfishContext>(
|
||||
options =>
|
||||
{
|
||||
options.UseSqlite(Configuration.GetConnectionString("rfdb"));
|
||||
options.EnableSensitiveDataLogging(false);
|
||||
}
|
||||
});
|
||||
|
||||
);
|
||||
|
||||
//Added this so that can access configuration from anywhere else
|
||||
//See authcontroller for usage
|
||||
services.AddSingleton<IConfiguration>(Configuration);
|
||||
|
||||
services.AddMvc();
|
||||
|
||||
//get the key from the appsettings.json file
|
||||
var secretKey = Configuration.GetSection("JWT").GetValue<string>("secret");
|
||||
var signingKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(secretKey));
|
||||
|
||||
services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
}).AddJwtBearer(options =>
|
||||
{
|
||||
// options.AutomaticAuthenticate = true;
|
||||
// options.AutomaticChallenge = true;
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
// Token signature will be verified using a private key.
|
||||
ValidateIssuerSigningKey = true,
|
||||
RequireSignedTokens = true,
|
||||
IssuerSigningKey = signingKey,
|
||||
ValidateIssuer = true,
|
||||
ValidIssuer = "rockfishCore",
|
||||
ValidateAudience = false,
|
||||
// ValidAudience = "https://yourapplication.example.com",
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
}).AddJwtBearer(options =>
|
||||
{
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
// Token signature will be verified using a private key.
|
||||
ValidateIssuerSigningKey = true,
|
||||
RequireSignedTokens = true,
|
||||
IssuerSigningKey = signingKey,
|
||||
ValidateIssuer = true,
|
||||
ValidIssuer = "rockfishCore",
|
||||
ValidateAudience = false,
|
||||
|
||||
//Note: these are all enabled in AyaNOva but were origionally disabled in rf
|
||||
// // Token will only be valid if not expired yet, with 5 minutes clock skew.
|
||||
// ValidateLifetime = true,
|
||||
// RequireExpirationTime = true,
|
||||
// ClockSkew = new TimeSpan(0, 5, 0),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
// Token will only be valid if not expired yet, with 5 minutes clock skew.
|
||||
// ValidateLifetime = true,
|
||||
// RequireExpirationTime = true,
|
||||
// ClockSkew = new TimeSpan(0, 5, 0),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, rockfishContext dbContext)
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, rockfishContext dbContext)
|
||||
{
|
||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
loggerFactory.AddDebug();
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
@@ -103,20 +101,145 @@ namespace rockfishCore
|
||||
}
|
||||
});
|
||||
app.UseAuthentication();
|
||||
app.UseMvc();
|
||||
//Check schema
|
||||
RfSchema.CheckAndUpdate(dbContext);
|
||||
|
||||
//bool bMM=RfMail.MailIsMirroringProperly();
|
||||
// try
|
||||
// {
|
||||
// var test = OpsDiagnostics.VerifyBackups();
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// string res = ex.Message;
|
||||
// }
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
}//eof
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// using System;
|
||||
// using System.Collections.Generic;
|
||||
// using System.Linq;
|
||||
// using System.Threading.Tasks;
|
||||
// using Microsoft.AspNetCore.Builder;
|
||||
// using Microsoft.AspNetCore.Hosting;
|
||||
// using Microsoft.Extensions.Configuration;
|
||||
// using Microsoft.Extensions.DependencyInjection;
|
||||
// using Microsoft.Extensions.Logging;
|
||||
|
||||
// //manually added
|
||||
// using Microsoft.EntityFrameworkCore;
|
||||
// using rockfishCore.Models;
|
||||
// using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
// using Microsoft.IdentityModel.Tokens;
|
||||
// using rockfishCore.Util;
|
||||
|
||||
// //added when upgrade to v2 of .netcore
|
||||
// using Microsoft.AspNetCore.Authentication;
|
||||
// //this comment added in windows with notepad++
|
||||
// //this comment added in Linux with vscode
|
||||
// namespace rockfishCore
|
||||
// {
|
||||
// public class Startup
|
||||
// {
|
||||
// public Startup(IHostingEnvironment env)
|
||||
// {
|
||||
// var builder = new ConfigurationBuilder()
|
||||
// .SetBasePath(env.ContentRootPath)
|
||||
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
// .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
// .AddEnvironmentVariables();
|
||||
// Configuration = builder.Build();
|
||||
// }
|
||||
|
||||
// public IConfigurationRoot Configuration { get; }
|
||||
|
||||
// // This method gets called by the runtime. Use this method to add services to the container.
|
||||
// public void ConfigureServices(IServiceCollection services)
|
||||
// {
|
||||
|
||||
// services.AddDbContext<rockfishContext>(
|
||||
// options =>
|
||||
// {
|
||||
// options.UseSqlite(Configuration.GetConnectionString("rfdb"));
|
||||
// options.EnableSensitiveDataLogging(false);
|
||||
// }
|
||||
|
||||
// );
|
||||
|
||||
// //Added this so that can access configuration from anywhere else
|
||||
// //See authcontroller for usage
|
||||
// services.AddSingleton<IConfiguration>(Configuration);
|
||||
|
||||
// services.AddMvc();
|
||||
|
||||
// //get the key from the appsettings.json file
|
||||
// var secretKey = Configuration.GetSection("JWT").GetValue<string>("secret");
|
||||
// var signingKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes(secretKey));
|
||||
|
||||
// services.AddAuthentication(options =>
|
||||
// {
|
||||
// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
// }).AddJwtBearer(options =>
|
||||
// {
|
||||
// // options.AutomaticAuthenticate = true;
|
||||
// // options.AutomaticChallenge = true;
|
||||
// options.TokenValidationParameters = new TokenValidationParameters
|
||||
// {
|
||||
// // Token signature will be verified using a private key.
|
||||
// ValidateIssuerSigningKey = true,
|
||||
// RequireSignedTokens = true,
|
||||
// IssuerSigningKey = signingKey,
|
||||
// ValidateIssuer = true,
|
||||
// ValidIssuer = "rockfishCore",
|
||||
// ValidateAudience = false,
|
||||
// // ValidAudience = "https://yourapplication.example.com",
|
||||
|
||||
// // Token will only be valid if not expired yet, with 5 minutes clock skew.
|
||||
// // ValidateLifetime = true,
|
||||
// // RequireExpirationTime = true,
|
||||
// // ClockSkew = new TimeSpan(0, 5, 0),
|
||||
// };
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
// public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, rockfishContext dbContext)
|
||||
// {
|
||||
// loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||
// loggerFactory.AddDebug();
|
||||
// app.UseDefaultFiles();
|
||||
// app.UseStaticFiles(new StaticFileOptions
|
||||
// {
|
||||
// OnPrepareResponse = context =>
|
||||
// {
|
||||
// if (context.File.Name == "default.htm")
|
||||
// {
|
||||
// context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
|
||||
// context.Context.Response.Headers.Add("Expires", "-1");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// app.UseAuthentication();
|
||||
// app.UseMvc();
|
||||
// //Check schema
|
||||
// RfSchema.CheckAndUpdate(dbContext);
|
||||
|
||||
// //bool bMM=RfMail.MailIsMirroringProperly();
|
||||
// // try
|
||||
// // {
|
||||
// // var test = OpsDiagnostics.VerifyBackups();
|
||||
// // }
|
||||
// // catch (Exception ex)
|
||||
// // {
|
||||
// // string res = ex.Message;
|
||||
// // }
|
||||
|
||||
// }//eof
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
@@ -8,12 +8,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- <PackageReference Include="AWSSDK.S3" Version="3.3.20" /> -->
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" />
|
||||
<PackageReference Include="jose-jwt" Version="2.4.0" />
|
||||
<PackageReference Include="mailkit" Version="2.0.5" />
|
||||
<PackageReference Include="AWSSDK.S3" Version="3.3.111.9" />
|
||||
<!-- <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" /> -->
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.4" />
|
||||
<PackageReference Include="jose-jwt" Version="2.5.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
|
||||
<PackageReference Include="mailkit" Version="2.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -119,8 +119,8 @@ namespace rockfishCore.Util
|
||||
bool trackDeliveryStatus = false, string CustomHeader = "", string CustomHeaderValue = "")
|
||||
{
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress(MessageFrom));
|
||||
message.To.Add(new MailboxAddress(MessageTo));
|
||||
message.From.Add(new MailboxAddress("",MessageFrom));
|
||||
message.To.Add(new MailboxAddress("",MessageTo));
|
||||
message.Subject = MessageSubject;
|
||||
|
||||
message.Body = new TextPart("plain")
|
||||
@@ -273,12 +273,12 @@ namespace rockfishCore.Util
|
||||
case rfMailAccount.sales:
|
||||
from_account = MAIL_ACCOUNT_SALES;
|
||||
from_account_password = MAIL_ACCOUNT_PASSWORD_SALES;
|
||||
from = new MailboxAddress(from_account);
|
||||
from = new MailboxAddress("",from_account);
|
||||
break;
|
||||
default:
|
||||
from_account = MAIL_ACCOUNT_SUPPORT;
|
||||
from_account_password = MAIL_ACCOUNT_PASSWORD_SUPPORT;
|
||||
from = new MailboxAddress(from_account);
|
||||
from = new MailboxAddress("",from_account);
|
||||
break;
|
||||
}
|
||||
reply.From.Add(from);
|
||||
@@ -520,7 +520,7 @@ namespace rockfishCore.Util
|
||||
string CustomHeader = "", string CustomHeaderValue = "")
|
||||
{
|
||||
var message = new MimeMessage();
|
||||
message.From.Add(new MailboxAddress(MessageFrom));
|
||||
message.From.Add(new MailboxAddress("",MessageFrom));
|
||||
|
||||
|
||||
//case 3512 handle more than one email in the address
|
||||
@@ -530,13 +530,13 @@ namespace rockfishCore.Util
|
||||
var addrs = MessageTo.Split(',');
|
||||
foreach (string addr in addrs)
|
||||
{
|
||||
mbAll.Add(new MailboxAddress(addr.Trim()));
|
||||
mbAll.Add(new MailboxAddress("",addr.Trim()));
|
||||
}
|
||||
message.To.AddRange(mbAll);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.To.Add(new MailboxAddress(MessageTo));
|
||||
message.To.Add(new MailboxAddress("",MessageTo));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user