httpntlm

package module
v0.0.0-...-9ad6f25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 7 Imported by: 0

README

go-http-ntlm

go-http-ntlm is a Go package that contains NTLM transport (http.RoundTripper implementation) for http.Client to make NTLM auth protected http requests.

Usage example

package main

import (
    "io/ioutil"
    "log"
    "net/http"
    "strings"

    "github.com/vadimi/go-http-ntlm/v2"
)

func main() {

    // configure http client
    client := http.Client{
        Transport: &httpntlm.NtlmTransport{
            Domain:   "mydomain",
            User:     "testuser",
            Password: "fish",
            // Configure RoundTripper if necessary, otherwise DefaultTransport is used
            RoundTripper: &http.Transport{
                // provide tls config
                TLSClientConfig: &tls.Config{},
                // other properties RoundTripper, see http.DefaultTransport
            },
        },
    }

    req, err := http.NewRequest("GET", "http://server/ntlm-auth-resource", strings.NewReader(""))
    resp, err := client.Do(req)

    if err != nil {
        log.Fatal(err)
    }

    defer func() {
        err := resp.Body.Close()
        if err != nil {
            log.Fatal(err)
        }
    }()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        log.Fatal(err)
    }

    log.Println(body)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// EncBase64 encodes bytes to base64 string
	EncBase64 = base64.StdEncoding.EncodeToString
	// DecBase64 decodes base64 string to bytes
	DecBase64 = base64.StdEncoding.DecodeString
)

Functions

func Negotiate

func Negotiate() []byte
Negotiate generates NTLM Negotiate type-1 message

for details see https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/b34032e5-3aae-4bc6-84c3-c6d80eadf7f2

Types

type NtlmTransport

type NtlmTransport struct {
	Domain      string
	User        string
	Password    string
	Workstation string
	http.RoundTripper
	Jar http.CookieJar
}

NtlmTransport is implementation of http.RoundTripper interface

func (NtlmTransport) RoundTrip

func (t NtlmTransport) RoundTrip(req *http.Request) (res *http.Response, err error)

RoundTrip method send http request and tries to perform NTLM authentication

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL