mirror of https://github.com/Squidex/squidex.git
16 changed files with 233 additions and 133 deletions
@ -0,0 +1,81 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Startup.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.IO; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Net.Http.Headers; |
||||
|
using Squidex.Areas.Frontend.Middlewares; |
||||
|
|
||||
|
namespace Squidex.Areas.Frontend |
||||
|
{ |
||||
|
public static class Startup |
||||
|
{ |
||||
|
public static void ConfigureFrontend(this IApplicationBuilder app) |
||||
|
{ |
||||
|
var environment = app.ApplicationServices.GetRequiredService<IHostingEnvironment>(); |
||||
|
|
||||
|
if (environment.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseMiddleware<WebpackMiddleware>(); |
||||
|
} |
||||
|
|
||||
|
app.Use((context, next) => |
||||
|
{ |
||||
|
if (context.Request.Path == "/client-callback-popup") |
||||
|
{ |
||||
|
context.Request.Path = new PathString("/client-callback-popup.html"); |
||||
|
} |
||||
|
else if (context.Request.Path == "/client-callback-silent") |
||||
|
{ |
||||
|
context.Request.Path = new PathString("/client-callback-silent.html"); |
||||
|
} |
||||
|
else if (!Path.HasExtension(context.Request.Path.Value)) |
||||
|
{ |
||||
|
if (environment.IsDevelopment()) |
||||
|
{ |
||||
|
context.Request.Path = new PathString("/index.html"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
context.Request.Path = new PathString("/build/index.html"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return next(); |
||||
|
}); |
||||
|
|
||||
|
app.UseStaticFiles(new StaticFileOptions |
||||
|
{ |
||||
|
OnPrepareResponse = context => |
||||
|
{ |
||||
|
var response = context.Context.Response; |
||||
|
var responseHeaders = response.GetTypedHeaders(); |
||||
|
|
||||
|
if (!string.Equals(response.ContentType, "text/html", StringComparison.OrdinalIgnoreCase)) |
||||
|
{ |
||||
|
responseHeaders.CacheControl = new CacheControlHeaderValue |
||||
|
{ |
||||
|
MaxAge = TimeSpan.FromDays(60) |
||||
|
}; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
responseHeaders.CacheControl = new CacheControlHeaderValue |
||||
|
{ |
||||
|
NoCache = true |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
// ==========================================================================
|
||||
|
// LazyClientStore.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Authentication; |
||||
|
using Microsoft.AspNetCore.Authentication.Cookies; |
||||
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Squidex.Shared.Identity; |
||||
|
|
||||
|
namespace Squidex.Areas.OrleansDashboard.Middlewares |
||||
|
{ |
||||
|
public sealed class OrleansDashboardAuthenticationMiddleware |
||||
|
{ |
||||
|
private readonly RequestDelegate next; |
||||
|
|
||||
|
public OrleansDashboardAuthenticationMiddleware(RequestDelegate next) |
||||
|
{ |
||||
|
this.next = next; |
||||
|
} |
||||
|
|
||||
|
public async Task Invoke(HttpContext context) |
||||
|
{ |
||||
|
var authentication = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); |
||||
|
|
||||
|
if (!authentication.Succeeded || !authentication.Principal.IsInRole(SquidexRoles.Administrator)) |
||||
|
{ |
||||
|
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties |
||||
|
{ |
||||
|
RedirectUri = context.Request.PathBase + context.Request.Path |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
await next(context); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Startup.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Orleans; |
||||
|
using Squidex.Areas.OrleansDashboard.Middlewares; |
||||
|
|
||||
|
namespace Squidex.Areas.OrleansDashboard |
||||
|
{ |
||||
|
public static class Startup |
||||
|
{ |
||||
|
public static void ConfigureOrleansDashboard(this IApplicationBuilder app) |
||||
|
{ |
||||
|
app.Map("/orleans", orleansApp => |
||||
|
{ |
||||
|
orleansApp.UseAuthentication(); |
||||
|
orleansApp.UseMiddleware<OrleansDashboardAuthenticationMiddleware>(); |
||||
|
orleansApp.UseOrleansDashboard(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<body> |
||||
|
<script src="/scripts/oidc-client.min.js"></script> |
||||
|
<script> |
||||
|
Oidc.Log.logger = console; |
||||
|
Oidc.Log.logLevel = Oidc.Log.INFO; |
||||
|
|
||||
|
new Oidc.UserManager().signinPopupCallback(); |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,12 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<body> |
||||
|
<script src="/scripts/oidc-client.min.js"></script> |
||||
|
<script> |
||||
|
Oidc.Log.logger = console; |
||||
|
Oidc.Log.logLevel = Oidc.Log.INFO; |
||||
|
|
||||
|
new Oidc.UserManager().signinSilentCallback(); |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
||||
Loading…
Reference in new issue