Skip to content

Instantly share code, notes, and snippets.

View khalidabuhakmeh's full-sized avatar
👨‍⚖️
talking & listening to developers

Khalid Abuhakmeh khalidabuhakmeh

👨‍⚖️
talking & listening to developers
View GitHub Profile
@khalidabuhakmeh
khalidabuhakmeh / gist:9412344
Created March 7, 2014 14:22
Refresh Claims for AuthenticationManager OWIN
public async Task Refresh(ClaimsIdentity claim, bool? rememberMe)
{
var current = _authenticationManager.User;
var remember = current.Claims.FirstOrDefault(x => x.Type == ClaimTypes.IsPersistent);
if (rememberMe.HasValue) {
// remember the "remember me" :)
claim.AddClaim(new Claim(ClaimTypes.IsPersistent, rememberMe.ToString()));
}
else if (claim != null) {
public class BusinessMappingTests
{
public BusinessMappingTests()
{
Mapper.Initialize(cfg => cfg.AddProfile<BusinessMappingProfile>());
Mapper.AssertConfigurationIsValid();
}
[Fact]
public void Can_map_editmodel_to_business()
PerfMatter.TitleResolver = DependencyResolver.Current.GetService<ITitleResolver>();
public class MyTitleResolver : ITitleResolver {
// pass in whatever values you need
// The FlushHead() method automatically copies over any ViewData/ViewBag state, accepts an optional title parameter as well an optional model parameter, if required. Pass it in here
public string Resolve(IDictionary<string,object> values) {
var title = "";
// Figure out the title based on the context
return title;
public class StructureMapDependencyResolver : ServiceLocatorImplBase
{
private const string StructuremapNestedContainerKey = "Structuremap.Nested.Container";
public IContainer Container { get; set; }
private HttpContextBase HttpContext
{
get
{
// All the user to register where the context comes from
### Keybase proof
I hereby claim:
* I am khalidabuhakmeh on github.
* I am khalidabuhakmeh (https://keybase.io/khalidabuhakmeh) on keybase.
* I have a public key whose fingerprint is 4292 F2BE 8F4F 22A3 7EB3 313C EE64 C1F6 9463 EB97
To claim this, I am signing this object:
@khalidabuhakmeh
khalidabuhakmeh / gist:376337ec06701b314f15
Created March 3, 2015 14:43
FluentValidation working with WebAPI
FluentValidationModelValidatorProvider.Configure(GlobalConfiguration.Configuration, config =>
{
config.ValidatorFactory = new WebApiValidatorFactory(GlobalConfiguration.Configuration);
});
public class WebApiValidatorFactory : ValidatorFactoryBase
{
private readonly HttpConfiguration _configuration;
public WebApiValidatorFactory(HttpConfiguration configuration)
For<HttpContext>().AlwaysUnique().Use(ctx => HttpContext.Current);
For<HttpRequestMessage>().AlwaysUnique().Use(ctx => ctx.GetInstance<HttpContext>().Items["MS_HttpRequestMessage"] as HttpRequestMessage);
For<UrlHelper>().AlwaysUnique().Use(ctx => new UrlHelper(ctx.GetInstance<HttpRequestMessage>()));
public static class SearchExtensions
{
public static IQueryable<T> Search<T>(this IQueryable<T> value, object search)
{
if (search == null)
{
return value;
}
var filterProperties = search
@khalidabuhakmeh
khalidabuhakmeh / ItsAllOk.cs
Created December 11, 2015 13:07
OctoKit is totally fine.
using System;
using Octokit;
using System.Linq;
public class Program
{
public static void Main()
{
var client = new GitHubClient(new ProductHeaderValue("test"));

Problem

We would like to secure sites hosted on IIS that may / or may not be written with ASP.NET. Additionally, these sites may not be applications we have complete control over (OSS project).

Proposed Solution

An OpenID Connect HttpModule client that can be added to any IIS hosted application via web.config and offer crude authentication. Crude authentication means setting a few basic rules in app settings: endpoints and claims. This would work with an ASP.NET application, NodeJs application, etc. Anything that can be hosted on IIS.

How This Problem Came About