Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jtblin/go-ldap-client
Simple ldap client to authenticate, retrieve basic information and groups for a user.
https://github.com/jtblin/go-ldap-client
Last synced: 5 days ago
JSON representation
Simple ldap client to authenticate, retrieve basic information and groups for a user.
- Host: GitHub
- URL: https://github.com/jtblin/go-ldap-client
- Owner: jtblin
- License: other
- Created: 2015-12-17T11:54:41.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-22T12:32:08.000Z (about 1 year ago)
- Last Synced: 2024-12-22T12:12:19.508Z (12 days ago)
- Language: Go
- Size: 7.81 KB
- Stars: 261
- Watchers: 15
- Forks: 90
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-ldap-client
Simple ldap client to authenticate, retrieve basic information and groups for a user.
# Usage
[Go Doc](https://godoc.org/github.com/jtblin/go-ldap-client)
See [example](example_test.go). The only external dependency is [gopkg.in/ldap.v2](http://gopkg.in/ldap.v2).
```golang
package mainimport (
"log""github.com/jtblin/go-ldap-client"
)func main() {
client := &ldap.LDAPClient{
Base: "dc=example,dc=com",
Host: "ldap.example.com",
Port: 389,
UseSSL: false,
BindDN: "uid=readonlysuer,ou=People,dc=example,dc=com",
BindPassword: "readonlypassword",
UserFilter: "(uid=%s)",
GroupFilter: "(memberUid=%s)",
Attributes: []string{"givenName", "sn", "mail", "uid"},
}
// It is the responsibility of the caller to close the connection
defer client.Close()ok, user, err := client.Authenticate("username", "password")
if err != nil {
log.Fatalf("Error authenticating user %s: %+v", "username", err)
}
if !ok {
log.Fatalf("Authenticating failed for user %s", "username")
}
log.Printf("User: %+v", user)
groups, err := client.GetGroupsOfUser("username")
if err != nil {
log.Fatalf("Error getting groups for user %s: %+v", "username", err)
}
log.Printf("Groups: %+v", groups)
}
```## SSL (ldaps)
If you use SSL, you will need to pass the server name for certificate verification
or skip domain name verification e.g.`client.ServerName = "ldap.example.com"`.# Why?
There are already [tons](https://godoc.org/?q=ldap) of ldap libraries for `golang` but most of them
are just forks of another one, most of them are too low level or too limited (e.g. do not return errors
which make it hard to troubleshoot issues).