Golang communicate with LDAP

Ok, so let's try authentication using github.com/go-ldap/ldap. First you need to create a an *ldap.Conn. I suggest using TLS, if your LDAP server supports it:

// TLS, for testing purposes disable certificate verification, check https://golang.org/pkg/crypto/tls/#Config for further information.
tlsConfig := &tls.Config{InsecureSkipVerify: true}
l, err := ldap.DialTLS("tcp", "ldap.example.com:636", tlsConfig)

// No TLS, not recommended
l, err := ldap.Dial("tcp", "ldap.example.com:389")

Now you should have an active connection to your LDAP server. Using this connection you have to execute a bind:

err := l.Bind("[email protected]", "password")
if err != nil {
    // error in ldap bind
    log.Println(err)
}
// successful bind

Tags:

Ldap

Go