ldap

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2020 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package ldap provides authentication strategy, to authenticate HTTP requests and builds, extracts user informations from LDAP Server.

Example
cfg := Config{
	BaseDN:       "dc=example,dc=org",
	BindDN:       "cn=readonly,dc=example,dc=org",
	Port:         "389",
	Host:         "127.0.0.1",
	BindPassword: "readonly",
	Filter:       "(cn=%s)",
}

r, _ := http.NewRequest("GET", "/", nil)
r.SetBasicAuth("admin", "admin")

info, err := New(&cfg).Authenticate(r.Context(), r)
fmt.Println(info, err != nil)
Output:

<nil> true

Index

Examples

Constants

View Source
const StrategyKey = auth.StrategyKey("LDAP.Strategy")

StrategyKey export identifier for the LDAP strategy, commonly used when enable/add strategy to go-guardian authenticator.

Variables

View Source
var ErrEntries = errors.New("LDAP: Serach user DN does not exist or too many entries returned")

ErrEntries is returned by ldap authenticate function, When search result return user DN does not exist or too many entries returned.

Functions

func New

func New(cfg *Config) auth.Strategy

New return new auth.Strategy.

func NewCached

func NewCached(cfg *Config, c store.Cache) auth.Strategy

NewCached return new auth.Strategy. The returned strategy, caches the authentication decision.

Types

type Config

type Config struct {
	// Port LDAP server port.
	Port string
	// Host LDAP server host.
	Host string
	// TLS configuration, if nil connect without TLS.
	TLS *tls.Config
	// BindDN represents LDAP DN for searching for the user DN.
	// Typically read only user DN.
	BindDN string
	// BindPassword LDAP password for searching for the user DN.
	// Typically read only user password.
	BindPassword string
	// Attributes used for users.
	Attributes []string
	// BaseDN LDAP domain to use for users.
	BaseDN string
	// Filter for the User Object Filter.
	// if username nedded more than once use fmt index pattern (%[1]s).
	// Otherwise %s.
	Filter string
}

Config define the configuration to connect to LDAP.

Jump to

Keyboard shortcuts

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