Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ions into dev
  • Loading branch information
WeihanLi committed Nov 13, 2024
2 parents abca00e + f6e95a1 commit 7ee75a2
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void OnAuthorization(AuthorizationFilterContext filterContext)
var isDefinedNoControl = filterContext.ActionDescriptor.IsDefined(typeof(NoAccessControlAttribute), true);

if (isDefinedNoControl) return;

var accessStrategy = filterContext.HttpContext.RequestServices.GetService<IResourceAccessStrategy>();
if (accessStrategy is null)
throw new InvalidOperationException("IResourceAccessStrategy not initialized,please register your ResourceAccessStrategy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static IAccessControlHelperBuilder AddAccessControlHelper<TResourceAccess
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configAction);

services.Configure(configAction);
return services.AddAccessControlHelper<TResourceAccessStrategy, TControlStrategy>();
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public static IAccessControlHelperBuilder AddAccessControlHelper(this IServiceCo
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configAction);

var option = new AccessControlOptions();
configAction.Invoke(option);
services.Configure(configAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Task Invoke(HttpContext context)
{
return _next(context);
}

context.Response.StatusCode = context.User is { Identity.IsAuthenticated: true } ? 403 : 401;
return _option.DefaultUnauthorizedOperation?.Invoke(context) ?? Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class HtmlHelperExtension
/// <param name="accessKey">accessKey</param>
/// <returns></returns>
public static IHtmlContent SparkActionLink(
this IHtmlHelper helper, string linkText, string actionName, string? controllerName = null,
this IHtmlHelper helper, string linkText, string actionName, string? controllerName = null,
object? routeValues = null, object? htmlAttributes = null, string? accessKey = null)
{
if (helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IControlAccessStrategy>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static AuthenticationBuilder AddApiKey(this AuthenticationBuilder builder
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configureOptions);

builder.Services.Configure(configureOptions);
return builder.AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(schema,
configureOptions);
Expand Down Expand Up @@ -98,7 +98,7 @@ public static AuthenticationBuilder AddHeader(this AuthenticationBuilder builder
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configureOptions);

builder.Services.Configure(configureOptions);
return builder.AddScheme<HeaderAuthenticationOptions, HeaderAuthenticationHandler>(schema,
configureOptions);
Expand Down Expand Up @@ -130,7 +130,7 @@ public static AuthenticationBuilder AddQuery(this AuthenticationBuilder builder,
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configureOptions);

builder.Services.Configure(configureOptions);
return builder.AddScheme<QueryAuthenticationOptions, QueryAuthenticationHandler>(schema,
configureOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static IServiceCollection AddJwtService(this IServiceCollection serviceCo
{
ArgumentNullException.ThrowIfNull(serviceCollection);
ArgumentNullException.ThrowIfNull(optionsAction);

serviceCollection.Configure(optionsAction);
serviceCollection.TryAddSingleton<ITokenService, JsonWebTokenService>();
serviceCollection.ConfigureOptions<JsonWebTokenOptionsSetup>();
Expand All @@ -29,7 +29,7 @@ public static IServiceCollection AddJwtServiceWithJwtBearerAuth(this IServiceCol
{
serviceCollection.Configure(jwtBearerOptionsSetup);
}

serviceCollection.ConfigureOptions<JwtBearerOptionsPostSetup>();
return serviceCollection.AddJwtService(optionsAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ private static void ProtectParams(JToken token, ITimeLimitedDataProtector protec
}

public static bool TryGetUnprotectedValue(this IDataProtector protector, ParamsProtectionOptions option,
string? value, [MaybeNullWhen(false)]out string unprotectedValue)
string? value, [MaybeNullWhen(false)] out string unprotectedValue)
{
unprotectedValue = value;
if (string.IsNullOrEmpty(value))
return false;

if (option is { AllowUnprotectedParams: true, ParamValueProtectFuncEnabled: true } && option.ParamValueNeedProtectFunc(value)
)
{
Expand Down
4 changes: 2 additions & 2 deletions src/WeihanLi.Web.Extensions/Extensions/EndpointExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static IEndpointConventionBuilder MapConfigInspector(this IEndpointRouteB
)
{
ArgumentNullException.ThrowIfNull(endpointRouteBuilder);

if (optionsConfigure is not null)
{
var options = endpointRouteBuilder.ServiceProvider.GetRequiredService<IOptions<ConfigInspectorOptions>>();
optionsConfigure(options.Value);
}

return endpointRouteBuilder.MapGet($"{path}/{{configKey?}}", async (context) =>
{
var options = context.RequestServices.GetRequiredService<IOptions<ConfigInspectorOptions>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static IApplicationBuilder UseHealthCheck(this IApplicationBuilder applic
{
checkFunc = _ => Task.FromResult(true);
}

async Task CheckFunc(HttpContext context, Func<Task> next)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static class HttpContextExtension
/// <param name="principal">principal</param>
/// <returns></returns>
public static T GetUserId<T>(this ClaimsPrincipal principal) => GetUserId(principal).ToOrDefault<T>()!;

public static T GetUserId<T>(this ClaimsPrincipal principal, string claimType)
=> GetUserId(principal, claimType).ToOrDefault<T>()!;

Expand Down

0 comments on commit 7ee75a2

Please sign in to comment.