Skip to content

Instantly share code, notes, and snippets.

@loudej
loudej / Chunked.cs
Created January 27, 2012 11:04
Comparison of chunked middleware
using System;
using System.Collections.Generic;
using Gate.Owin;
using System.Text;
namespace Gate.Middleware
{
public static class Chunked
{
public static IAppBuilder UseChunked(this IAppBuilder builder)
@loudej
loudej / Application.shade
Created April 12, 2012 21:21
".shade" left-offset spark syntax
html
head
meta charset="utf-8"
title =ViewBag.Title
link href="~/Content/Site.css" rel="stylesheet" type="text/css"
script src="~/Scripts/jquery-1.5.1.min.js" type="text/javascript" |
script src="~/Scripts/modernizr-1.7.min.js" type="text/javascript" |
body div.page
header
#title h1 |My MVC Application
@loudej
loudej / gist:2651684
Created May 10, 2012 07:29
run owin-sandbox
git clone https://github.com/owin/owin-sandbox.git
cd owin-sandbox
build start
(or simply)
git clone https://github.com/owin/owin-sandbox.git && owin-sandbox\build start
(then browse http://localhost:3001 and http://localhost:3002, etc)
@loudej
loudej / option-a.cs
Created June 12, 2012 20:56
Unify Request and Response representation
namespace Owin
{
public delegate void AppDelegate(
IDictionary<string, object> env,
ResultDelegate result,
Action<Exception> fault);
public delegate void ResultDelegate(
string status,
IDictionary<string, string[]> headers,
@loudej
loudej / NoOwinDllReference.cs
Created July 31, 2012 17:26
Samples of middleware
using AppAction = Func<
IDictionary<string, object>,
IDictionary<string, string[]>,
Stream,
Task<Tuple<
IDictionary<string, object>,
int,
IDictionary<string, string[]>,
Func<Stream, Task>>>>;
@loudej
loudej / ILogger.cs
Last active December 12, 2015 05:18
using System;
using System.Diagnostics;
using System.IO;
namespace KatanaApplication33
{
public class Example
{
private ILogger _logger;
@loudej
loudej / Default.aspx
Created March 20, 2013 21:55
auth sample
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Katana.Experimental.WebApp.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
@loudej
loudej / Startup.cs
Last active December 16, 2015 13:19
OWIN Hello World
using Owin;
namespace HelloOwin
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
// example of a filter - writeline each request
app.UseFilter(req => req.TraceOutput.WriteLine(
@loudej
loudej / auth.md
Last active December 24, 2015 08:29

Auth flows

Okay! Here are the environment keys and flows that authentication middleware follow.

Any API you see on IAuthenticationManager, IOwinContext, IOwinRequest, IOwinResponse are only syntax sugar and utility code around these env keys and values.

SignIn and SignOut

Simplest cases first: the application wants to sign in or sign out the user.

And for the highest degree of compatability consider sticking to the owin func<dict, task> signature as a middleware constructor, and add an extension method to IAppBuilder for discoverability.

In the following example, a Microsoft.Owin.dll reference is used only for the OwinContext/OwinRequest/OwinResponse helper classes. Those will work regardless of if the host is aware of the OwinMiddleware base class. That reference can be avoided altogether if your project has its own internal copy of an environment wrapper class it uses, instead of OwinContext.

Also in the example, an Owin.dll reference is used to add app.UseExample([options]) extension method to IAppBuilder. Without that extension method the site author could still call app.Use([options]) or app.Use(typeof(ExampleMiddleware)[, options]), but the discoverability is not good.

So, we’d suggest middleware authors take a dependency on Owin.dll to provide an IAppBuilder extension method at a minimum, and host authors to use IAppBuilder