How to Perform NTLM Authentication in Go HTTP Requests with System Credentials?

Barbara Streisand
Release: 2024-10-26 11:46:30
Original
917 people have browsed it

How to Perform NTLM Authentication in Go HTTP Requests with System Credentials?

NTLM Authentication in Go HTTP Requests with System Credentials

In this question, the user seeks guidance on performing Windows NTML authentication in a Go HTTP request using the system credentials of the calling user. They provide examples from C# and Python that demonstrate how to achieve this in those languages.

The solution lies in utilizing the go-ole library, which enables the use of WinHTTPRequest in Go. By following a similar approach as the Python example, it is possible to implement NTML authentication with system credentials in Go.

Here is the provided code snippet in Go that accomplishes this:

<code class="go">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())
}</code>
Copy after login

This code initializes the WinHTTPRequest object, sets the auto logon policy to use the current user's credentials, opens a GET request to the specified URL, sends the request, and retrieves the response text.

The above is the detailed content of How to Perform NTLM Authentication in Go HTTP Requests with System Credentials?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!