246 lines
9.0 KiB
C#
246 lines
9.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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;
|
|
|
|
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 Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
namespace rockfishCore
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
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.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),
|
|
};
|
|
});
|
|
|
|
|
|
}
|
|
|
|
// 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)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
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();
|
|
//Check schema
|
|
RfSchema.CheckAndUpdate(dbContext);
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
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
|
|
// }
|
|
// }
|