goad

package module
v0.0.0-...-a261351 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 6 Imported by: 0

README

GoDoc

About

goad is simple wrapper around go-ad-auth the great go-ad-auth library to help with authentication and search in Active Directory.

Installing

go get github.com/vasiliyaltunin/goad

Dependencies:

If you have any issues or questions create an issue.

Setup

Package use init() to connect and bind to you AD server, so before use package create or update ".env" file in root of you progect folder!

In this file add folowing strings:

Name Description
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.
AD_SERVER_PORT AD server port - defaults to 389
AD_BASEDN base path to place, where all you users stored in AD.
AD_BIND_LOGIN user login, that used to bind to LDAPS.
AD_BIND_PASS user password, that used to bind to LDAPS.

Example:

AD_SERVER_NAME=SRV1.ACME.CONTOSO.COM
AD_SERVER_PORT=389
AD_BASEDN=OU=USERS,DC=ACME,DC=CONTOSO,DC=COM
AD_BIND_LOGIN=ldap-bind-acme
AD_BIND_PASS=xxxxxxxxxxxxxxxxxxxxxxxx

Usage

You can easy check auth with single function

Example:

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!")
}

You can read user attributes from AD

Example:

userName := "acme"
val := goad.GetAllUserAttrs(userName)

fmt.Println(val.GetAttr("sn"))
fmt.Println(val.GetGroups())
fmt.Println(val.GetMail())

You can check is user in some group

Example:

userName := "acme"
val := goad.GetAllUserAttrs(userName)
access := val.IsInGroup("acme-admins")

if access == true {
    fmt.Println("ACCESS GRANTED!")
} else {
    fmt.Println("ACCESS DINIED!")
}

See more examples on GoDoc.

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAuth

func CheckAuth(username, password string) (bool, error)

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:

func GetConfig

func GetConfig() *auth.Config

GetConfig - returns config

func GetConn

func GetConn() *auth.Conn

GetConn - returns connection

Types

type UserAttibutes

type UserAttibutes map[string][]string

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:

Jump to

Keyboard shortcuts

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