dappy

package module
v0.0.0-...-4d42df7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2019 License: MIT Imports: 5 Imported by: 2

README

Basic LDAP client for Go

GoDoc Report Card

LDAP is complicated. Many times, all you really need to do is authenticate users with it. This package boils down LDAP functionality to User Authentication, that's it.

Thanks to https://github.com/go-ldap/ldap

go get github.com/nerney/dappy

Example:

package main

import (
	"log"

	"github.com/nerney/dappy"
)

func main() {
	var client dappy.Client
	var err error

	// create a new client
	if client, err = dappy.New(dappy.Config{
		BaseDN: "dc=example,dc=com",
		Filter: "uid",
		ROUser: dappy.User{Name: "cn=read-only-admin,dc=example,dc=com", Pass: "password"},
		Host:   "ldap.forumsys.com:389",
	}); err != nil {
		panic(err)
	}

	// username and password to authenticate
	username := "tesla"
	password := "password"

	// attempt the authentication
	if err := client.Auth(username, password); err != nil {
		panic(err)
	} else {
		log.Println("Success!")
	}
}

Documentation

Overview

Package dappy provides an ldap client for simple ldap authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Auth(username, password string) error
}

Client interface performs ldap auth operation

func New

func New(config Config) (Client, error)

New dappy client with the provided config If the configuration provided is invalid, or dappy is unable to connect with the config provided, an error will be returned

type Config

type Config struct {
	BaseDN string // base directory, ex. "CN=Users,DC=Company"
	ROUser User   // the read-only user for initial bind
	Host   string // the ldap host and port, ex. "ldap.directory.com:389"
	Filter string // defaults to "sAMAccountName" for AD
}

Config to provide a dappy client. All fields are required, except for Filter.

type User

type User struct {
	Name string
	Pass string
}

User holds the name and pass required for initial read-only bind.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL