Skip to content

Instantly share code, notes, and snippets.

View jamescrowley's full-sized avatar

James Crowley jamescrowley

View GitHub Profile
var google = new GoogleOAuth2AuthenticationOptions
{
ClientId = ConfigurationManager.AppSettings.Get("Google.ClientId"),
ClientSecret = ConfigurationManager.AppSettings.Get("Google.ClientSecret"),
CallbackPath = new PathString("/callback"),
AuthenticationType = "Google",
SignInAsAuthenticationType = signInAsType
};
app.UseGoogleAuthentication(google);
@jamescrowley
jamescrowley / TaskExtensions.cs
Last active August 29, 2015 14:05
Async retry
public static class TaskExtensions
{
public static async Task RetryWhileException<T>(this Task transientOperation, int retryCount, TimeSpan retryDelay) where T:Exception
{
int currentRetry = 0;
while (true)
{
try
{
@jamescrowley
jamescrowley / DoesntWork.fsx
Created July 16, 2014 10:17
PowerShell / F# Make weirdness
Target "PowerShell" (fun _ ->
let result = ExecProcess (fun info ->
info.FileName <- "powershell.exe"
info.WorkingDirectory <- (currentDirectory @@ "deploy")
info.Arguments <- "-ExecutionPolicy RemoteSigned -Command \"Import-Module Carbon\"") System.TimeSpan.MaxValue
if result <> 0 then failwithf "Error deploying local"
)
@jamescrowley
jamescrowley / web.config
Created June 25, 2014 16:44
Owin/IIS OPTIONS problem
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="owin:HandleAllRequests" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
@jamescrowley
jamescrowley / ErrorHandlingTests.cs
Created June 16, 2014 12:13
ErrorHandlingTests
namespace FundApps.DocumentGenerator.FeatureTests.OwinMiddleware
{
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FundApps.DocumentGenerator.Web.Infrastructure.Owin;
@jamescrowley
jamescrowley / GlobalExceptionHandlingMiddleware.cs
Last active August 29, 2015 14:02
GlobalExceptionHandlingMiddleware
public class GlobalExceptionHandlingMiddleware : OwinMiddleware
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public GlobalExceptionHandlingMiddleware(OwinMiddleware next) : base(next)
{
}
public override async Task Invoke(IOwinContext context)
{
try
@jamescrowley
jamescrowley / 01-Startup.cs
Last active July 12, 2016 21:59
Global OWIN handling of errors & page not found
public class Startup
{
public void Configuration(IAppBuilder app)
{
app
.Use<StatusCodeFromExceptionMiddleware>()
.UseNancy();
}
}
@jamescrowley
jamescrowley / Maybe.cs
Created May 24, 2014 11:16
Maybe from Lokad
// Imported from Lokad.Shared, 2011-02-08
using System;
namespace Lokad.Cloud.Storage
{
/// <summary>
/// Helper class that indicates nullable value in a good-citizenship code
/// </summary>
/// <typeparam name="T">underlying type</typeparam>
@jamescrowley
jamescrowley / StatelessAuth.cs
Created May 24, 2014 11:02
Owin Stateless auth
using System.Security.Claims;
using Microsoft.Owin;
namespace Owin.StatelessAuth
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class StatelessAuth : OwinMiddleware
@jamescrowley
jamescrowley / JsonValidatingModelBinder.cs
Last active September 29, 2019 09:48
Validating JSON with ASP.NET request validation
public class JsonValidatingModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var result = base.BindModel(controllerContext, bindingContext);
if (!IsJsonRequest(controllerContext))
{
return result;
}
if (!bindingContext.ModelMetadata.RequestValidationEnabled)