This repository contains a collection of middleware functions that let you add informations about a Windows User (identified by Windows Authentication) to a Go context, or obtain the port used by IIS if that is how you serve your application.
There are two main packages:
goav1
: contains middleware functions that are specific for Goa v1http
: contains standard HTTP middleware functions, that can be used with Goa v3.
IMPORTANT NOTE: these middleware functions will work as expected only if compiled for Windows. If you try to use them on a Unix environment, you will obtain mock data.
-
Install HttpPlatformHandler to use IIS as a reverse proxy
-
Configure your
web.config
so that Windows Auth tokens are forwarded to your API, for example:<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/> </handlers> <httpPlatform processPath="C:\path\to\your\binary.exe" arguments="--arguments --for --your --binary" startupRetryCount="3" stdoutLogEnabled="true" forwardWindowsAuthToken="true"/><!-- This is very important --> </system.webServer> </configuration>
-
Listen to the port reserved by IIS
IIS will pass the expected port you should listen to via an environment variable. For convenience, you can use an helper function provided by this package:
import "github.com/top-solution/go-iis-auth/ad" ... portToListenTo := ad.GetIISPortWithFallback(9000) // this will return either 9000 or the actual port required by IIS
-
Import the package by using:
import ( admiddleware "github.com/top-solution/go-iis-auth/goav1" )
-
Mount the middleware as show in the following example:
service.Use(admiddleware.WithUser())
-
Import the package by using:
import ( admiddleware "github.com/top-solution/go-iis-auth/http" )
-
Mount the middleware as shown in the following example:
var handler http.Handler = mux { handler = admiddleware.WithUser()(handler) }