Skip to content

Instantly share code, notes, and snippets.

@danesparza
Last active April 20, 2017 14:53
Show Gist options
  • Save danesparza/6172e5d0e8ca03094849a5b2bac461d4 to your computer and use it in GitHub Desktop.
Save danesparza/6172e5d0e8ca03094849a5b2bac461d4 to your computer and use it in GitHub Desktop.
Using OLE to provide windows authenticated http requests
package main
import (
"fmt"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
func main() {
ole.CoInitialize(0)
defer ole.CoUninitialize()
unknown, _ := oleutil.CreateObject("WinHTTP.WinHTTPRequest.5.1")
request, _ := unknown.QueryInterface(ole.IID_IDispatch)
oleutil.CallMethod(request, "SetAutoLogonPolicy", 0)
oleutil.CallMethod(request, "Open", "GET", "http://your-windows-authenticated/website", false)
oleutil.CallMethod(request, "Send")
resp := oleutil.MustGetProperty(request, "ResponseText")
fmt.Println(resp.ToString())
}
@danesparza
Copy link
Author

Ugly (since you're essentially relying on the Windows subsystem to create a browser request), but confirmed it works -- when other solutions haven't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment