Adding support for .NET 8.0 LTS, renaming private fields to start with underscore
This commit is contained in:
@@ -45,13 +45,13 @@ namespace Microsoft.AspNetCore.Authorization
|
||||
if (isAllowAnonymous)
|
||||
return;
|
||||
|
||||
if (!context.HttpContext.Request.Headers.ContainsKey("Authorization"))
|
||||
if (!context.HttpContext.Request.Headers.TryGetValue("Authorization", out var authHeaderValue))
|
||||
{
|
||||
SetAuthenticateRequest(context);
|
||||
return;
|
||||
}
|
||||
|
||||
var authHeader = AuthenticationHeaderValue.Parse(context.HttpContext.Request.Headers["Authorization"]);
|
||||
var authHeader = AuthenticationHeaderValue.Parse(authHeaderValue);
|
||||
byte[] decoded = Convert.FromBase64String(authHeader.Parameter);
|
||||
string plain = Encoding.UTF8.GetString(decoded);
|
||||
|
||||
@@ -84,22 +84,22 @@ namespace Microsoft.AspNetCore.Authorization
|
||||
: validator.Realm
|
||||
: Realm;
|
||||
|
||||
context.HttpContext.Response.Headers["WWW-Authenticate"] = "Basic";
|
||||
context.HttpContext.Response.Headers.WWWAuthenticate = "Basic";
|
||||
if (!string.IsNullOrWhiteSpace(realm))
|
||||
context.HttpContext.Response.Headers["WWW-Authenticate"] = $"Basic realm=\"{realm.Trim().Replace("\"", "")}\"";
|
||||
context.HttpContext.Response.Headers.WWWAuthenticate = $"Basic realm=\"{realm.Trim().Replace("\"", "")}\"";
|
||||
|
||||
context.HttpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||
context.Result = new StatusCodeResult(StatusCodes.Status401Unauthorized);
|
||||
}
|
||||
|
||||
private async Task<ClaimsPrincipal> TrySetHttpUser(AuthorizationFilterContext context)
|
||||
private static async Task<ClaimsPrincipal> TrySetHttpUser(AuthorizationFilterContext context)
|
||||
{
|
||||
var logger = context.HttpContext.RequestServices.GetService<ILogger<BasicAuthenticationAttribute>>();
|
||||
try
|
||||
{
|
||||
if (context.HttpContext.Request.Headers.ContainsKey("Authorization"))
|
||||
if (context.HttpContext.Request.Headers.TryGetValue("Authorization", out var authHeaderValue))
|
||||
{
|
||||
var authHeader = AuthenticationHeaderValue.Parse(context.HttpContext.Request.Headers["Authorization"]);
|
||||
var authHeader = AuthenticationHeaderValue.Parse(authHeaderValue);
|
||||
byte[] decoded = Convert.FromBase64String(authHeader.Parameter);
|
||||
string plain = Encoding.UTF8.GetString(decoded);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters
|
||||
|
||||
private const string VerificationUrl = "https://www.google.com/recaptcha/api/siteverify";
|
||||
|
||||
private string privateKey;
|
||||
private string _privateKey;
|
||||
|
||||
/// <summary>
|
||||
/// Executes the validattion in background.
|
||||
@@ -61,9 +61,9 @@ namespace Microsoft.AspNetCore.Mvc.Filters
|
||||
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
var configuration = context.HttpContext.RequestServices.GetService<IConfiguration>();
|
||||
privateKey = configuration?.GetValue<string>("Google:ReCaptcha:PrivateKey");
|
||||
_privateKey = configuration?.GetValue<string>("Google:ReCaptcha:PrivateKey");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(privateKey))
|
||||
if (string.IsNullOrWhiteSpace(_privateKey))
|
||||
return;
|
||||
|
||||
await DoValidation(context).ConfigureAwait(false);
|
||||
@@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters
|
||||
using var httpClient = new HttpClient();
|
||||
var param = new Dictionary<string, string>
|
||||
{
|
||||
{ "secret", privateKey },
|
||||
{ "secret", _privateKey },
|
||||
{ "response", token }
|
||||
};
|
||||
var response = await httpClient.PostAsync(VerificationUrl, new FormUrlEncodedContent(param)).ConfigureAwait(false);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Filters
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Filters
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user