Browse Source

Merge branch 'master' of github.com:Squidex/squidex

pull/1186/head
Sebastian Stehle 1 year ago
parent
commit
58de0f3b4e
  1. 5
      backend/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaActionHandler.cs
  2. 41
      backend/src/Squidex/Areas/IdentityServer/Controllers/Error/ErrorController.cs
  3. 5
      backend/src/Squidex/Config/Authentication/OidcHandler.cs
  4. 2
      backend/src/Squidex/Config/MyIdentityOptions.cs
  5. 1
      backend/src/Squidex/appsettings.json

5
backend/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaActionHandler.cs

@ -83,7 +83,7 @@ public sealed class AlgoliaActionHandler(RuleEventFormatter formatter, IScriptEn
{
AppId = action.AppId,
ApiKey = action.ApiKey,
Content = serializer.Serialize(content, true),
Content = delete ? null : serializer.Serialize(content, true),
ContentId = contentId,
IndexName = indexName
};
@ -100,7 +100,6 @@ public sealed class AlgoliaActionHandler(RuleEventFormatter formatter, IScriptEn
}
var index = await clients.GetClientAsync((job.AppId, job.ApiKey, job.IndexName));
try
{
if (job.Content != null)
@ -147,5 +146,5 @@ public sealed class AlgoliaJob
public string IndexName { get; set; }
public string Content { get; set; }
public string? Content { get; set; }
}

41
backend/src/Squidex/Areas/IdentityServer/Controllers/Error/ErrorController.cs

@ -5,15 +5,20 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Text.RegularExpressions;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Squidex.Config;
using Squidex.Infrastructure;
namespace Squidex.Areas.IdentityServer.Controllers.Error;
public sealed class ErrorController : IdentityServerController
public sealed class ErrorController(IOptions<MyIdentityOptions> identityOptions) : IdentityServerController
{
private readonly MyIdentityOptions identityOptions = identityOptions.Value;
[Route("error/")]
public async Task<IActionResult> Error(string? errorId = null)
{
@ -32,14 +37,12 @@ public sealed class ErrorController : IdentityServerController
}
var source = HttpContext.Features.Get<IExceptionHandlerFeature>();
if (source == null)
{
return View("Error", vm);
}
var exception = source.Error;
while (exception?.InnerException != null)
{
exception = exception.InnerException;
@ -49,10 +52,42 @@ public sealed class ErrorController : IdentityServerController
{
vm.ErrorMessage = exception?.Message;
}
else if (TryGetMappedError(exception, out var mappedError))
{
vm.ErrorMessage = mappedError;
}
return View("Error", vm);
}
private bool TryGetMappedError(Exception? exception, out string message)
{
message = null!;
if (exception == null || identityOptions.OidcErrorMap == null || identityOptions.OidcErrorMap.Count == 0)
{
return false;
}
foreach (var (pattern, value) in identityOptions.OidcErrorMap)
{
try
{
if (Regex.IsMatch(exception.Message, pattern))
{
message = value;
return true;
}
}
catch
{
continue;
}
}
return false;
}
private static bool IsTestEndpoint(IExceptionHandlerFeature source)
{
return source.Endpoint is RouteEndpoint route && route.RoutePattern.RawText == "identity-server/test";

5
backend/src/Squidex/Config/Authentication/OidcHandler.cs

@ -34,6 +34,11 @@ public sealed class OidcHandler(MyIdentityOptions options) : OpenIdConnectEvents
return base.TokenValidated(context);
}
public override Task AuthenticationFailed(AuthenticationFailedContext context)
{
return base.AuthenticationFailed(context);
}
public override Task RedirectToIdentityProviderForSignOut(RedirectContext context)
{
if (!string.IsNullOrEmpty(options.OidcOnSignoutRedirectUrl))

2
backend/src/Squidex/Config/MyIdentityOptions.cs

@ -55,6 +55,8 @@ public sealed class MyIdentityOptions
public string OidcResponseType { get; set; }
public Dictionary<string, string>? OidcErrorMap { get; set; }
public string? OidcOnSignoutRedirectUrl { get; set; }
public string[] OidcScopes { get; set; }

1
backend/src/Squidex/appsettings.json

@ -651,6 +651,7 @@
"oidcClient": "",
"oidcSecret": "",
"oidcPrompt": null,
"oidcErrorMap": null,
"oidcMetadataAddress": "",
"oidcScopes": [
"email"

Loading…
Cancel
Save