etitcombe / windowsauthmw

Go middleware which integrates with the Windows authentication token received from HttpPlatformHandler.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

windowsauthmw

A Go middleware which adds the Windows domain and user name to the request context. It assumes the web application is running under IIS via the HttpPlatformHandler.

It is based on windowsauthtoken by Michael Collins.

There is currently only one method: AddDomainUser which takes and returns an http.Handler.

Wrap your mux with it at the beginning or close to the beginning of your middleware chain. You'll want this invoked early so that the information is added to the Context before you need to use it.

srv := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: windowsauthmw.AddDomainUser(mux)}

The middlware adds the domain and user name to the context in this format: Domain\Username

It doesn't offer a way to get the value out of the context. That is the responsibility of the application code. Use the provided DomainUserKey to get the value from the context:

ctx := r.Context()
domainUser := ctx.Value(windowsauthmw.DomainUserKey).(string)

About

Go middleware which integrates with the Windows authentication token received from HttpPlatformHandler.

License:MIT License


Languages

Language:Go 100.0%