mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
// ==========================================================================
|
|
// 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;
|
|
|
|
namespace Squidex.Areas.Portal.Middlewares
|
|
{
|
|
public sealed class PortalDashboardAuthenticationMiddleware
|
|
{
|
|
private readonly RequestDelegate next;
|
|
|
|
public PortalDashboardAuthenticationMiddleware(RequestDelegate next)
|
|
{
|
|
this.next = next;
|
|
}
|
|
|
|
public async Task Invoke(HttpContext context)
|
|
{
|
|
var authentication = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
|
|
if (!authentication.Succeeded)
|
|
{
|
|
var properties = new AuthenticationProperties
|
|
{
|
|
RedirectUri = context.Request.PathBase + context.Request.Path
|
|
};
|
|
|
|
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, properties);
|
|
}
|
|
else
|
|
{
|
|
context.User = authentication.Principal;
|
|
|
|
await next(context);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|