Documentation
¶
Overview ¶
Package windowsauthtoken implements Windows user authentication using Windows domain credentials for Go web applications. Package windowsauthtoken is designed to work when the web application is being hosted by IIS on a Windows Server connected to a Windows domain using the HttpPlatformHandler module to forward requests from IIS to the web application.
HttpPlatformHandler supports a configuration option that forwards the handle for the Windows token for the authenticated user to the Go web application by attaching the X-IIS-WindowsAuthToken HTTP header to the forwarded request. Package windowsauthtoken implements a middleware handler that will execute on every request to extract the handle from the HTTP header, obtain the name of the authenticated user, and make the Windows username available to the web application.
HttpPlatformHandler will pass the handle on every request that is forwarded to the web application, and it is the responsibility of the web application to close the handle at the end of the request. This is handled automatically by the middleware. But because the handle is passed on every request, it is recommended that you wrap the http.DefaultServeMux handler or your root handler with the middleware. For example:
package main
import (
"net/http"
"github.com/mfcollins3/windowsauthtoken"
)
func main() {
// TODO: register HTTP handlers with net/http
rootHandler := windowsauthtoken.Handler(
http.DefaultServeMux,
func(username string) error {
// Store username somewhere for the request. For example,
// you can use Gorilla Toolkit's context package to store
// the username in the request.
return nil
})
log.Fatal(http.ListenAndServe(":8080", rootHandler))
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns an HTTP handler that will process the token for the authenticated user that is passed to the web application in the X-IIS-WindowsAuthToken HTTP header. Handler will obtain the Windows username for the authenticated user and will pass the username to the web application using the callback parameter.
Types ¶
type Callback ¶
Callback is an application-provided function that the web application provides to the Handler middleware. The callback function will be called on each request after the username for the authenticated Windows user has been obtained. The application can use the callback to store the username for processing within the request.
type TokenValue ¶
type TokenValue int
TokenValue is an enumeration that specifies which user token value should be passed to the callback handler by the Windows authentication token handler. The current options are either to send the DOMAIN\Username vale or the user's SID to the callback handler.
const ( // TokenUsername indicates that the Windows authentication token handler // will invoke the callback handler with the Windows username // (DOMAIN\Username) for the authenticated user. TokenUsername TokenValue = iota // TokenSid indicates that the Windows authentication token handler will // invoke the callback handler with the authenticated user's SID as a // string. TokenSid )