V10: fix build warnings in Web.BackOffice (#12479)

* Run code cleanup

* Start manual run

* Finish dotnet format + manual cleanup

* Fix up after merge

* Fix substrings changed to [..]

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
Nikolaj Geisle
2022-06-20 08:37:17 +02:00
committed by GitHub
parent 7688c61621
commit e762fa91bc
234 changed files with 28037 additions and 27527 deletions

View File

@@ -1,52 +1,53 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Newtonsoft.Json;
using Umbraco.Cms.Core.Security;
using Umbraco.Extensions;
using HttpRequestExtensions = Umbraco.Extensions.HttpRequestExtensions;
namespace Umbraco.Cms.Web.BackOffice.Middleware
namespace Umbraco.Cms.Web.BackOffice.Middleware;
/// <summary>
/// Used to handle errors registered by external login providers
/// </summary>
/// <remarks>
/// When an external login provider registers an error with
/// <see cref="Extensions.HttpContextExtensions.SetExternalLoginProviderErrors" /> during the OAuth process,
/// this middleware will detect that, store the errors into cookie data and redirect to the back office login so we can
/// read the errors back out.
/// </remarks>
public class BackOfficeExternalLoginProviderErrorMiddleware : IMiddleware
{
/// <summary>
/// Used to handle errors registered by external login providers
/// </summary>
/// <remarks>
/// When an external login provider registers an error with <see cref="Extensions.HttpContextExtensions.SetExternalLoginProviderErrors"/> during the OAuth process,
/// this middleware will detect that, store the errors into cookie data and redirect to the back office login so we can read the errors back out.
/// </remarks>
public class BackOfficeExternalLoginProviderErrorMiddleware : IMiddleware
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
var shortCircuit = false;
if (!context.Request.IsClientSideRequest())
{
var shortCircuit = false;
if (!HttpRequestExtensions.IsClientSideRequest(context.Request))
// check if we have any errors registered
BackOfficeExternalLoginProviderErrors? errors = context.GetExternalLoginProviderErrors();
if (errors != null)
{
// check if we have any errors registered
var errors = context.GetExternalLoginProviderErrors();
if (errors != null)
{
shortCircuit = true;
shortCircuit = true;
var serialized = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(errors)));
var serialized = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(errors)));
context.Response.Cookies.Append(ViewDataExtensions.TokenExternalSignInError, serialized, new CookieOptions
context.Response.Cookies.Append(
ViewDataExtensions.TokenExternalSignInError,
serialized,
new CookieOptions
{
Expires = DateTime.Now.AddMinutes(5),
HttpOnly = true,
Secure = context.Request.IsHttps
});
context.Response.Redirect(context.Request.GetEncodedUrl());
}
context.Response.Redirect(context.Request.GetEncodedUrl());
}
}
if (next != null && !shortCircuit)
{
await next(context);
}
if (next != null && !shortCircuit)
{
await next(context);
}
}
}

View File

@@ -1,22 +1,23 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
namespace Umbraco.Cms.Web.BackOffice.Middleware
namespace Umbraco.Cms.Web.BackOffice.Middleware;
/// <summary>
/// Ensures the Keep Alive middleware is part of
/// </summary>
public sealed class ConfigureGlobalOptionsForKeepAliveMiddlware : IPostConfigureOptions<GlobalSettings>
{
private readonly IOptions<KeepAliveSettings> _keepAliveSettings;
public ConfigureGlobalOptionsForKeepAliveMiddlware(IOptions<KeepAliveSettings> keepAliveSettings) =>
_keepAliveSettings = keepAliveSettings;
/// <summary>
/// Ensures the Keep Alive middleware is part of
/// Append the keep alive ping url to the reserved URLs
/// </summary>
public sealed class ConfigureGlobalOptionsForKeepAliveMiddlware : IPostConfigureOptions<GlobalSettings>
{
private readonly IOptions<KeepAliveSettings> _keepAliveSettings;
public ConfigureGlobalOptionsForKeepAliveMiddlware(IOptions<KeepAliveSettings> keepAliveSettings) => _keepAliveSettings = keepAliveSettings;
/// <summary>
/// Append the keep alive ping url to the reserved URLs
/// </summary>
/// <param name="name"></param>
/// <param name="options"></param>
public void PostConfigure(string name, GlobalSettings options) => options.ReservedUrls += _keepAliveSettings.Value.KeepAlivePingUrl;
}
/// <param name="name"></param>
/// <param name="options"></param>
public void PostConfigure(string name, GlobalSettings options) =>
options.ReservedUrls += _keepAliveSettings.Value.KeepAlivePingUrl;
}

View File

@@ -1,26 +1,22 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Umbraco.Cms.Web.BackOffice.Middleware
namespace Umbraco.Cms.Web.BackOffice.Middleware;
/// <summary>
/// Used for the Umbraco keep alive service. This is terminating middleware.
/// </summary>
public class KeepAliveMiddleware : IMiddleware
{
/// <summary>
/// Used for the Umbraco keep alive service. This is terminating middleware.
/// </summary>
public class KeepAliveMiddleware : IMiddleware
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
if (HttpMethods.IsGet(context.Request.Method) || HttpMethods.IsHead(context.Request.Method))
{
if (HttpMethods.IsGet(context.Request.Method) || HttpMethods.IsHead(context.Request.Method))
{
context.Response.StatusCode = StatusCodes.Status200OK;
await context.Response.WriteAsync("I'm alive");
}
else
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
}
context.Response.StatusCode = StatusCodes.Status200OK;
await context.Response.WriteAsync("I'm alive");
}
else
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
}
}
}