Windows system credentials in Go HTTP NTLM requests

前端 未结 1 735
Happy的楠姐
Happy的楠姐 2021-01-20 13:28

I am looking for the path of least resistance for doing NTLM authentication in a Go HTTP request using the system credentials of the Windows user calling the application.

1条回答
  •  面向向阳花
    2021-01-20 13:49

    After digging into it a bit further, it looks like go-ole can be utilized to make use of WinHTTPRequest in the same way as the Python example in the question. Ignoring all error catching,

    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://example.com", false)
        oleutil.CallMethod(request, "Send")
        resp := oleutil.MustGetProperty(request, "ResponseText")
        fmt.Println(resp.ToString())
    }
    

    0 讨论(0)
提交回复
热议问题