|
|
|
@ -4,6 +4,7 @@ using System.Security.Cryptography.X509Certificates;
|
|
|
|
using Google.Apis.Util.Store;
|
|
|
|
using Google.Apis.Util.Store;
|
|
|
|
using IdentityServer8;
|
|
|
|
using IdentityServer8;
|
|
|
|
using IdentityServer8.Services;
|
|
|
|
using IdentityServer8.Services;
|
|
|
|
|
|
|
|
using IdentityServerHost.Quickstart.UI;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
@ -138,28 +139,28 @@ public static class HostingExtensions
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IServiceCollection services = LoadConfiguration(builder);
|
|
|
|
IServiceCollection services = LoadConfiguration(builder);
|
|
|
|
|
|
|
|
|
|
|
|
services.AddRazorPages();
|
|
|
|
//services.AddRazorPages();
|
|
|
|
|
|
|
|
|
|
|
|
services.AddSignalR(o =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
o.EnableDetailedErrors = true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddIdentityDBAndStores(builder).AddDefaultTokenProviders();
|
|
|
|
|
|
|
|
AddIdentityServer(builder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.AddSession();
|
|
|
|
services.AddSession();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO .AddServerSideSessionStore<YavscServerSideSessionStore>()
|
|
|
|
// TODO .AddServerSideSessionStore<YavscServerSideSessionStore>()
|
|
|
|
|
|
|
|
|
|
|
|
AddAuthentication(services, builder.Configuration);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the system clock service
|
|
|
|
// Add the system clock service
|
|
|
|
_ = services.AddSingleton<ISystemClock, SystemClock>();
|
|
|
|
_ = services.AddSingleton<ISystemClock, SystemClock>();
|
|
|
|
_ = services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
|
|
|
_ = services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
|
|
|
_ = services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
|
|
|
_ = services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
|
|
|
_ = services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
|
|
|
_ = services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddIdentityDBAndStores(builder).AddDefaultTokenProviders();
|
|
|
|
|
|
|
|
AddIdentityServer(builder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.AddSignalR(o =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
o.EnableDetailedErrors = true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
services.AddMvc(config =>
|
|
|
|
services.AddMvc(config =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* var policy = new AuthorizationPolicyBuilder()
|
|
|
|
/* var policy = new AuthorizationPolicyBuilder()
|
|
|
|
@ -207,6 +208,7 @@ public static class HostingExtensions
|
|
|
|
services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
|
|
|
|
services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddAuthentication(builder);
|
|
|
|
// accepts any access token issued by identity server
|
|
|
|
// accepts any access token issued by identity server
|
|
|
|
|
|
|
|
|
|
|
|
return builder.Build();
|
|
|
|
return builder.Build();
|
|
|
|
@ -296,20 +298,16 @@ public static class HostingExtensions
|
|
|
|
return services;
|
|
|
|
return services;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void AddAuthentication(IServiceCollection services, IConfigurationRoot configurationRoot)
|
|
|
|
private static void AddAuthentication(WebApplicationBuilder builder)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string? googleClientId = configurationRoot["Authentication:Google:ClientId"];
|
|
|
|
IServiceCollection services=builder.Services;
|
|
|
|
|
|
|
|
IConfigurationRoot configurationRoot=builder.Configuration;
|
|
|
|
|
|
|
|
string? googleClientId = configurationRoot["Authentication:Google:ClientId"];
|
|
|
|
string? googleClientSecret = configurationRoot["Authentication:Google:ClientSecret"];
|
|
|
|
string? googleClientSecret = configurationRoot["Authentication:Google:ClientSecret"];
|
|
|
|
|
|
|
|
|
|
|
|
var authenticationBuilder = services.AddAuthentication()
|
|
|
|
var authenticationBuilder = services.AddAuthentication();
|
|
|
|
.AddJwtBearer("Bearer", options =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options.IncludeErrorDetails = true;
|
|
|
|
|
|
|
|
options.Authority = "https://localhost:5001";
|
|
|
|
|
|
|
|
options.TokenValidationParameters =
|
|
|
|
|
|
|
|
new() { ValidateAudience = false };
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (googleClientId!=null && googleClientSecret!=null)
|
|
|
|
authenticationBuilder.AddGoogle(options =>
|
|
|
|
authenticationBuilder.AddGoogle(options =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
|
|
|
|
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
|
|
|
|
@ -323,13 +321,23 @@ public static class HostingExtensions
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private static IIdentityServerBuilder AddIdentityServer(WebApplicationBuilder builder)
|
|
|
|
private static IIdentityServerBuilder AddIdentityServer(WebApplicationBuilder builder)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var identityServerBuilder = builder.Services.AddIdentityServer()
|
|
|
|
builder.Services.AddTransient<IProfileService,ProfileService>();
|
|
|
|
|
|
|
|
var identityServerBuilder = builder.Services.AddIdentityServer(options =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options.Events.RaiseErrorEvents = true;
|
|
|
|
|
|
|
|
options.Events.RaiseInformationEvents = true;
|
|
|
|
|
|
|
|
options.Events.RaiseFailureEvents = true;
|
|
|
|
|
|
|
|
options.Events.RaiseSuccessEvents = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// see https://IdentityServer8.readthedocs.io/en/latest/topics/resources.html
|
|
|
|
|
|
|
|
options.EmitStaticAudienceClaim = true;
|
|
|
|
|
|
|
|
})
|
|
|
|
.AddInMemoryIdentityResources(Config.IdentityResources)
|
|
|
|
.AddInMemoryIdentityResources(Config.IdentityResources)
|
|
|
|
.AddInMemoryClients(Config.Clients)
|
|
|
|
.AddInMemoryClients(Config.Clients)
|
|
|
|
.AddInMemoryApiScopes(Config.ApiScopes)
|
|
|
|
.AddInMemoryApiScopes(Config.ApiScopes)
|
|
|
|
|
|
|
|
|
|
|
|
.AddAspNetIdentity<ApplicationUser>()
|
|
|
|
.AddAspNetIdentity<ApplicationUser>()
|
|
|
|
// .AddProfileService<ProfileService>()
|
|
|
|
.AddProfileService<ProfileService>()
|
|
|
|
.AddJwtBearerClientAuthentication()
|
|
|
|
|
|
|
|
;
|
|
|
|
;
|
|
|
|
if (builder.Environment.IsDevelopment())
|
|
|
|
if (builder.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -381,7 +389,7 @@ public static class HostingExtensions
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static WebApplication ConfigurePipeline(this WebApplication app)
|
|
|
|
internal static WebApplication ConfigurePipeline(this WebApplication app)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
@ -398,13 +406,10 @@ public static class HostingExtensions
|
|
|
|
app.UseIdentityServer();
|
|
|
|
app.UseIdentityServer();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseCors("default");
|
|
|
|
app.UseCors("default");
|
|
|
|
app.MapControllerRoute(
|
|
|
|
app.MapDefaultControllerRoute();
|
|
|
|
name: "default",
|
|
|
|
//pp.MapRazorPages();
|
|
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
|
|
|
app.MapRazorPages()
|
|
|
|
|
|
|
|
.RequireAuthorization();
|
|
|
|
|
|
|
|
app.MapHub<ChatHub>("/chatHub");
|
|
|
|
app.MapHub<ChatHub>("/chatHub");
|
|
|
|
app.MapAreaControllerRoute("api", "api", "~/api/{controller}/{action}/{id?}");
|
|
|
|
|
|
|
|
ConfigureWorkflow();
|
|
|
|
ConfigureWorkflow();
|
|
|
|
var services = app.Services;
|
|
|
|
var services = app.Services;
|
|
|
|
ILoggerFactory loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
|
|
|
ILoggerFactory loggerFactory = services.GetRequiredService<ILoggerFactory>();
|
|
|
|
|