Skip to content

Instantly share code, notes, and snippets.

@sfreiberg
Created August 16, 2012 18:23
Show Gist options
  • Save sfreiberg/3372371 to your computer and use it in GitHub Desktop.
Save sfreiberg/3372371 to your computer and use it in GitHub Desktop.
LDAP authentication in Go
package main
import (
"github.com/jbcrail/ldap"
"fmt"
)
func main() {
server := "ldap01.example.com:389"
username := "username"
password := "password"
dn := "uid=%s,cn=users,dc=example,dc=com"
ldapConn, err := ldap.Dial("tcp", server)
if err != nil {
fmt.Println(err)
return
}
ldapUser := fmt.Sprintf(dn, username)
err = ldapConn.Bind(ldapUser, password)
if err != nil {
fmt.Println(err)
return
} else {
fmt.Println("Not to get cocky but I think it worked!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment