Skip to content

Instantly share code, notes, and snippets.

View wcabus's full-sized avatar
👋

Wesley Cabus wcabus

👋
View GitHub Profile
@wcabus
wcabus / SecurityExtensions.cs
Created February 6, 2026 13:24
C#14 extensions for the ClaimsPrincipal, ClaimsIdentity and AuthenticationProperties types, adding both static methods and useful properties.
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
namespace Duende.Extensions;
internal static class SecurityExtensions
{
private static readonly ClaimsPrincipal Anonymous = new(new ClaimsIdentity());
extension(ClaimsPrincipal)
@wcabus
wcabus / Benchmark.cs
Created February 3, 2026 15:34
.NET 10 deabstraction benchmark sample
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Running;
// ReSharper disable ArrangeObjectCreationWhenTypeEvident
/*
To run these benchmarks, you'll need to add some target frameworks in the .csproj file and add the BenchmarkDotNet package reference:
@wcabus
wcabus / CustomAuthorizeRequestValidator.cs
Created May 9, 2025 08:35
Custom authorize request validator to limit supported grant_type and PCKE method sample
using Duende.IdentityModel;
using Duende.IdentityServer.Validation;
namespace Sample.Idsrv.Validation;
/*
* To register this custom validator, use "AddCustomAuthorizeRequestValidator" when configuring IdentityServer:
*
* builder.Service.AddIdentityServer()
* .AddCustomAuthorizeRequestValidator<LimitedAuthorizeRequestValidator>();
/// <summary>
/// The RolesAttribute extends the <see cref="AuthorizeAttribute"/> by allowing you to just assign a list of strings.
/// </summary>
public class RolesAttribute : AuthorizeAttribute
{
public RolesAttribute(params string[] roles)
{
if (roles == null)
throw new ArgumentNullException("roles", "roles can not be a null reference.");
@wcabus
wcabus / SortableBindingList.vb
Last active March 18, 2016 23:33
SortableBindingList is a list that supports sorting its items and filtering them.
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Reflection
Imports System.Linq
Imports System.Linq.Dynamic
''' <summary>
''' SortableBindingList is a list that supports sorting its items and filtering them.
''' When binding a <see cref="System.Collections.Generic.List(Of T)"/> to a <see cref="System.Windows.Forms.DataGridView"/>, you can not sort by clicking on the columns
''' or filter the list. With this list, you can.