...

Source file src/github.com/Azure/go-ntlmssp/authheader.go

Documentation: github.com/Azure/go-ntlmssp

     1  package ntlmssp
     2  
     3  import (
     4  	"encoding/base64"
     5  	"strings"
     6  )
     7  
     8  type authheader []string
     9  
    10  func (h authheader) IsBasic() bool {
    11  	for _, s := range h {
    12  		if strings.HasPrefix(string(s), "Basic ") {
    13  			return true
    14  		}
    15  	}
    16  	return false
    17  }
    18  
    19  func (h authheader) Basic() string {
    20  	for _, s := range h {
    21  		if strings.HasPrefix(string(s), "Basic ") {
    22  			return s
    23  		}
    24  	}
    25  	return ""
    26  }
    27  
    28  func (h authheader) IsNegotiate() bool {
    29  	for _, s := range h {
    30  		if strings.HasPrefix(string(s), "Negotiate") {
    31  			return true
    32  		}
    33  	}
    34  	return false
    35  }
    36  
    37  func (h authheader) IsNTLM() bool {
    38  	for _, s := range h {
    39  		if strings.HasPrefix(string(s), "NTLM") {
    40  			return true
    41  		}
    42  	}
    43  	return false
    44  }
    45  
    46  func (h authheader) GetData() ([]byte, error) {
    47  	for _, s := range h {
    48  		if strings.HasPrefix(string(s), "NTLM") || strings.HasPrefix(string(s), "Negotiate") || strings.HasPrefix(string(s), "Basic ") {
    49  			p := strings.Split(string(s), " ")
    50  			if len(p) < 2 {
    51  				return nil, nil
    52  			}
    53  			return base64.StdEncoding.DecodeString(string(p[1]))
    54  		}
    55  	}
    56  	return nil, nil
    57  }
    58  
    59  func (h authheader) GetBasicCreds() (username, password string, err error) {
    60  	d, err := h.GetData()
    61  	if err != nil {
    62  		return "", "", err
    63  	}
    64  	parts := strings.SplitN(string(d), ":", 2)
    65  	return parts[0], parts[1], nil
    66  }
    67  

View as plain text