ldap

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: MIT Imports: 8 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

This section is empty.

Variables

View Source
var ErrEntries = errors.New("strategies/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 GetAuthenticateFunc

func GetAuthenticateFunc(cfg *Config, opts ...auth.Option) basic.AuthenticateFunc

GetAuthenticateFunc return function to authenticate request using LDAP. The returned function typically used with the basic strategy.

func New

func New(cfg *Config, opts ...auth.Option) auth.Strategy

New return strategy authenticate request using LDAP. New is similar to Basic.New().

func NewCached

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

NewCached return strategy authenticate request using LDAP. The returned strategy, caches the authentication decision. New is similar to Basic.NewCached().

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