Documentation ¶
Overview ¶
Package ldap4gin is authenticator for gin framework using ldap server
Index ¶
Constants ¶
View Source
const SessionKeyName = "ldap4gin_user"
SessionKeyName names key used to store user profile in session
Variables ¶
This section is empty.
Functions ¶
func GetDefaultFields ¶
func GetDefaultFields() []string
GetDefaultFields returns fields we extract from LDAP by default
Types ¶
type Authenticator ¶
type Authenticator struct { // LDAPConn is ldap connection being used LDAPConn *ldap.Conn // contains filtered or unexported fields }
Authenticator links ldap and gin context together
func New ¶
func New(opts Options) (a *Authenticator, err error)
New creates new authenticator using options provided
func (*Authenticator) Authorize ¶
func (a *Authenticator) Authorize(c *gin.Context, username, password string) (err error)
Authorize tries to find user in ldap database, check his/her password via `bind` and populate session, if password matches
type Options ¶
type Options struct { // Debug outputs debugging information, better leave it to false Debug bool //ConnectionString depicts how we dial LDAP server, something like ldap://127.0.0.1:389 or ldaps://ldap.example.org:636 ConnectionString string // UserBaseTpl is template to extract user profiles by UID, for example "uid=%s,ou=people,dc=example,dc=org", UserBaseTpl string // TLS is configuration for encryption to use TLS *tls.Config // StartTLS shows, do we need to execute StartTLS or not StartTLS bool // ExtraFields is array of fields, we also extract from database. NOTICE - if you add too many fields, it can hit session size limits! ExtraFields []string }
Options depicts parameters used to instantiate Authenticator
type User ¶
type User struct { // General DN string // dn: uid=sveta,ou=people,dc=vodolaz095,dc=life UID string //uid: sveta // Names GivenName string // `givenname` - Svetlana CommonName string // `cn` - Svetlana Belaya Initials string // `initials` - SA Surname string // `sn` - Belaya // work specific Organization string // o: R&D OrganizationUnit string // Laboratory 47 Title string // title: developer Description string // description: writes code // Internet related Website string // labeleduri: https://vodolaz095.life Emails []string // `mail` user can have few emails // Linux specific UIDNumber uint64 // uidnumber 1000 GIDNumber uint64 // gidnumber 1000 HomeDirectory string // homedirectory: /home/sveta LoginShell string // loginshell - /bin/bash // Raw entry extracted from LDAP Entry *ldap.Entry }
User depicts profile of authorized user
Click to show internal directories.
Click to hide internal directories.