first commit -push
This commit is contained in:
21
RobotNet.IdentityServer/Helpers/AsyncEnumerableExtensions.cs
Normal file
21
RobotNet.IdentityServer/Helpers/AsyncEnumerableExtensions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace RobotNet.IdentityServer.Helpers;
|
||||
|
||||
public static class AsyncEnumerableExtensions
|
||||
{
|
||||
public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source)
|
||||
{
|
||||
return source == null ? throw new ArgumentNullException(nameof(source)) : ExecuteAsync();
|
||||
|
||||
async Task<List<T>> ExecuteAsync()
|
||||
{
|
||||
var list = new List<T>();
|
||||
|
||||
await foreach (var element in source)
|
||||
{
|
||||
list.Add(element);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||||
|
||||
namespace RobotNet.IdentityServer.Helpers;
|
||||
|
||||
public sealed class FormValueRequiredAttribute(string name) : ActionMethodSelectorAttribute
|
||||
{
|
||||
private readonly string _name = name;
|
||||
|
||||
public override bool IsValidForRequest(RouteContext context, ActionDescriptor action)
|
||||
{
|
||||
if (string.Equals(context.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(context.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(context.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(context.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(context.HttpContext.Request.ContentType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!context.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(context.HttpContext.Request.Form[_name]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user