Documentation ¶
Overview ¶
Package goad provides a a tools to authennicate users in Active Directory (AD) and read user info from AD.
Imortant!
Before use package create or update ".env" file in root of you progect folder!
In this file add folowing strings:
1. AD_SERVER_NAME - AD server name, keep in mind, you must use FQDN for server name, or you can't connect to server with StartTLS.
Example:
AD_SERVER_NAME=SRV1.ACME.CONTOSO.COM
2. AD_SERVER_PORT - AD server port is 389.
Example:
AD_SERVER_PORT=389
3. AD_BASEDN - base path to place, where all you users stored in AD.
Example:
AD_BASEDN=OU=USERS,DC=ACME,DC=CONTOSO,DC=COM
4. AD_BIND_LOGIN - user login, that used to bind to LDAPS.
Example:
AD_BIND_LOGIN=ldap-bind-acme
5. AD_BIND_PASS - user password, that used to bind to LDAPS.
Example:
AD_BIND_PASS=xxxxxxxxxxxxxxxxxxxxxxxx
Package use init() to connect and bind to you AD server.
After connection established you can use functions like CheckAuth or GetAllUserAttrs to get info from AD or auth you users!
Index ¶
- func CheckAuth(username, password string) (bool, error)
- func GetConfig() *auth.Config
- func GetConn() *auth.Conn
- type UserAttibutes
- func (attrs *UserAttibutes) GetAttr(name string) []string
- func (attrs *UserAttibutes) GetCompany() string
- func (attrs *UserAttibutes) GetDepartment() string
- func (attrs *UserAttibutes) GetDisplayName() string
- func (attrs *UserAttibutes) GetGivenName() string
- func (attrs *UserAttibutes) GetGroups() []string
- func (attrs *UserAttibutes) GetInitials() string
- func (attrs *UserAttibutes) GetMail() string
- func (attrs *UserAttibutes) GetName() string
- func (attrs *UserAttibutes) GetStreetAddress() string
- func (attrs *UserAttibutes) GetTelephoneNumber() string
- func (attrs *UserAttibutes) GetTitle() string
- func (attrs *UserAttibutes) GetUserPrincipalName() string
- func (attrs *UserAttibutes) IsInGroup(groupName string) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAuth ¶
CheckAuth - check user auth in AD
Example ¶
package main import ( "log" "vasiliyaltunin/goad" ) func main() { username := "acme" password := "x1x2x3x4x5" result, err := goad.CheckAuth(username, password) if err != nil { log.Println("Error connecting :", err) return } if result { log.Println(username + " auth complete!") } else { log.Println(username + " access denied!") } }
Output:
Types ¶
type UserAttibutes ¶
UserAttibutes - user attributes map
func GetAllUserAttrs ¶
func GetAllUserAttrs(userName string) UserAttibutes
GetAllUserAttrs - get all user attribute
Example ¶
package main import ( "fmt" "vasiliyaltunin/goad" ) func main() { userName := "acme" val := goad.GetAllUserAttrs(userName) fmt.Println(val.GetAttr("sn")) fmt.Println(val.GetGroups()) fmt.Println(val.GetMail()) }
Output:
func (*UserAttibutes) GetAttr ¶
func (attrs *UserAttibutes) GetAttr(name string) []string
GetAttr - get user attr
Example ¶
package main import ( "fmt" "vasiliyaltunin/goad" ) func main() { userName := "acme" val := goad.GetAllUserAttrs(userName) fmt.Println(val.GetAttr("sn")) }
Output:
func (*UserAttibutes) GetCompany ¶
func (attrs *UserAttibutes) GetCompany() string
GetCompany - get user company
func (*UserAttibutes) GetDepartment ¶
func (attrs *UserAttibutes) GetDepartment() string
GetDepartment - get user department
func (*UserAttibutes) GetDisplayName ¶
func (attrs *UserAttibutes) GetDisplayName() string
GetDisplayName - get user Display Name
func (*UserAttibutes) GetGivenName ¶
func (attrs *UserAttibutes) GetGivenName() string
GetGivenName - get user given Name
func (*UserAttibutes) GetGroups ¶
func (attrs *UserAttibutes) GetGroups() []string
GetGroups - get user groups
func (*UserAttibutes) GetInitials ¶
func (attrs *UserAttibutes) GetInitials() string
GetInitials - get user Initials
func (*UserAttibutes) GetMail ¶
func (attrs *UserAttibutes) GetMail() string
GetMail - get user Mail
func (*UserAttibutes) GetName ¶
func (attrs *UserAttibutes) GetName() string
GetName - get user Name
func (*UserAttibutes) GetStreetAddress ¶
func (attrs *UserAttibutes) GetStreetAddress() string
GetStreetAddress - get user StreetAddress
func (*UserAttibutes) GetTelephoneNumber ¶
func (attrs *UserAttibutes) GetTelephoneNumber() string
GetTelephoneNumber - get user TelephoneNumber
func (*UserAttibutes) GetTitle ¶
func (attrs *UserAttibutes) GetTitle() string
GetTitle - get user Title
func (*UserAttibutes) GetUserPrincipalName ¶
func (attrs *UserAttibutes) GetUserPrincipalName() string
GetUserPrincipalName - get UserPrincipalName
func (*UserAttibutes) IsInGroup ¶
func (attrs *UserAttibutes) IsInGroup(groupName string) bool
IsInGroup - checks is user in given group
Example ¶
package main import ( "fmt" "vasiliyaltunin/goad" ) func main() { userName := "acme" val := goad.GetAllUserAttrs(userName) access := val.IsInGroup("acme-admins") if access == true { fmt.Println("ACCESS GRANTED!") } else { fmt.Println("ACCESS DINIED!") } }
Output: