Skip to content

Instantly share code, notes, and snippets.

@loudej
loudej / stuff.yaml
Created December 17, 2021 02:11
resource list
apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
# need a project
- apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
kind: Project
metadata:
name: scale-demo-192837
namespace: projects
@loudej
loudej / kpt-oci-example.sh
Created December 10, 2021 02:48
kpt oci example usage
function section() {
echo "$(tput setaf 6)$@$(tput sgr0)" 1>&2
}
function blueprint_clone() {
rm -r gke
section "New clone of gke at v0.3.0"
@loudej
loudej / example.json
Created October 1, 2021 06:29
example.json
{
"schemes": [],
"swagger": "2.0",
"info": {
"description": "# Overall api docs\n\nCan be used to do things.\n\n",
"title": "Swagger Example API",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",

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

@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.

@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 / 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 / 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 / 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 / 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,