Skip to content

Instantly share code, notes, and snippets.

@pmhsfelix
pmhsfelix / gist:a19a88a1995ae7cf053f
Created June 7, 2015 21:28
Wrapping services in IdentityServer
// definition
public static class IdentityServerServiceFactoryExtensions
{
public static void Wrap<T>(this IdentityServerServiceFactory fact,
Func<T, T> wrapper,
Func<IdentityServerServiceFactory,Registration<T>> getter,
Action<IdentityServerServiceFactory,Registration<T>> setter)
where T: class
{
fact.Register(new HelperRegistration<T>(getter(fact), GetRegistrationNameFor(typeof(T))));
@pmhsfelix
pmhsfelix / gist:232ee8a51e17204a31d1
Last active August 29, 2015 14:06
HttpWebRequest ServerCertificateValidationCallback and connection reuse
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Xunit;
namespace CertificateValidationAndConnections
{
public class CertificateValidationAndConnectionsFacts
{
@pmhsfelix
pmhsfelix / gist:008a393013294e6223c1
Created August 23, 2014 17:22
Can_use_TypeConverter_to_handle_simple_values
// based on http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
// and http://blogs.msdn.com/b/jmstall/archive/2012/04/20/how-to-bind-to-custom-objects-in-action-signatures-in-mvc-webapi.aspx
public class Can_use_TypeConverter_to_handle_simple_values
{
[TypeConverter(typeof(LocationTypeConverter))]
public class Location
{
public double Latitude { get; set; }
public double Longitude { get; set; }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Routing;
namespace Drum.Example.Controllers
{
@pmhsfelix
pmhsfelix / gist:859f1f736c13efd6b66f
Created May 14, 2014 15:48
Controller registration using autofac
var config = new HttpConfiguration();
var builder = new ContainerBuilder();
foreach (var type in config.Services
.GetHttpControllerSelector()
.GetControllerMapping().Select(p => p.Value.ControllerType))
{
builder.RegisterType(type);
}
@pmhsfelix
pmhsfelix / gist:4eee4a6b152942dc15e0
Created May 11, 2014 22:57
Parent-child routing with ASP.NET Web API. Too "hackish"?
public class ParentChildController : ApiController
{
public string Get(int pid, int cid)
{
return string.Format("{0}:{1}",pid,cid);
}
}
class ParentChildRoutingTranslator : DelegatingHandler
{
----
HTTP/1.1 401 Unauthorized
...
WWW-Authenticate: Basic realm="Web API Book"
...
----
----
GET /resource HTTP/1.1
@pmhsfelix
pmhsfelix / gist:7720474
Created November 30, 2013 15:32
Web API related talks at NDC London 2013
  • Wednesday
    • 10:20 - "ASP.NET Web API 2: HTTP Services for the Modern Web and Mobile Applications", Dan Roth
    • 11:40 - "Scripting your web API development using scriptcs", Glenn Block
    • 13:40 - "The missing link – hypermedia in Web API.", Darrel Miller
    • 15:00 - "API Client library V2", Darrel Miller
    • 16:20 - "ASP.NET and OWIN - Better Together", Dan Roth
  • Thursday
    • 9:00 - "A deep dive into the ASP.NET Web API runtime architecture", Pedro Felix
    • 10:20 - "Pragmatic ASP.NET Web API Solutions - beyond ValuesController", Christian Weyer
    • 11:40 - "Securing ASP.NET Web API (v2)", Dominick Baier
@pmhsfelix
pmhsfelix / gist:6148160
Last active November 22, 2016 16:25
Katana based HTTP Basic Authentication middleware, mostly for learning purposes
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Infrastructure;
using Owin;
[Fact]
public async Task Fact()
{
await OwinTester.Run(
useConfiguration: app =>
{
app.UseBasicAuthentication(Options);
},
useRequest: () =>
{