Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LDAP authendication using goLang

I am trying to authenticate with LDAP server using goLang also trying to search the user. I am new to goLang and LDAP so I pulled GitHub code. While trying with below code, I am getting error in authentication

func ExampleLDAPClient_Authenticate() {
    client := &ldap.LDAPClient{
        Base:         "cn=admin,dc=testing,dc=io",
        Host:         "52.51.245.219",
        Port:         389,
        UseSSL:       false,
        BindDN:       "cn=admin,dc=testing,dc=io",
        BindPassword: "test123",
        UserFilter:   "(uid='*api*')",
        // GroupFilter:  "(memberUid=%s)",
        Attributes: []string{"givenName", "sn", "mail", "uid"},
    }
    defer client.Close()
    username := "cn=admin,dc=testing,dc=io"
    password := "test123"
    ok, user, err := client.Authenticate(username, password)
    if err != nil {
        log.Fatalf("Error authenticating user %s: %+v", "*cn=admin,dc=testing,dc=io*", err)
    }
    if !ok {
        log.Fatalf("Authenticating failed for user %s", "*cn=admin,dc=testing,dc=io*")
    }
    log.Printf("User: %+v", user)
}
go run example.go
    2016/10/06 23:52:25 Error authenticating user *cn=admin,dc=testing,dc=io*: LDAP Result Code 201 "": ldap: finished compiling filter with extra at end: %!(EXTRA string=bmui)

Note: LDAP server working with http connection

Could anyone help me to fix this...

like image 409
Prakash26790 Avatar asked Nov 09 '22 07:11

Prakash26790


1 Answers

What library is this?

I have used http://gopkg.in/ldap.v2 and in my case it was working well (with OpenLDAP server at least). It may be worth trying it - it seems to be the most used library.

like image 97
Petar Donchev Avatar answered Nov 15 '22 06:11

Petar Donchev