• Stars
    star
    169
  • Rank 224,453 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Active Directory authentication library for Go

pkg.go.dev

About

go-ad-auth is a simple wrapper around the great ldap library to help with Active Directory authentication.

Installing

Using Go Modules:

go get github.com/korylprince/go-ad-auth/v3

Using gopkg.in:

go get gopkg.in/korylprince/go-ad-auth.v3

Dependencies:

If you have any issues or questions create an issue.

API Versions

You should update to the v3 API when possible. The new API is cleaner, more idiomatic, exposes a lot more functionality, and is fully testable.

v3 was created to support Go Modules, so it is backwards compatible with v2. However, updates made to v3 are not backported to v2.

The v3 API is almost a complete rewrite of the older gopkg.in/korylprince/go-ad-auth.v1 API. There are similarities, but v3 is not backwards-compatible.

One notable difference to be careful of is that while v1's Login will return false if the user is not in the specified group, v3's AuthenticateExtended will return true if the user authenticated successfully, regardless if they were in any of the specified groups or not.

Usage

Example:

config := &auth.Config{
    Server:   "ldap.example.com",
    Port:     389,
    BaseDN:   "OU=Users,DC=example,DC=com",
    Security: auth.SecurityStartTLS,
}

username := "user"
password := "pass"

status, err := auth.Authenticate(config, username, password)

if err != nil {
    //handle err
    return
}

if !status {
    //handle failed authentication
    return
}

See more advanced examples on go.dev.

Testing

go test -v

Most tests will be skipped unless you supply the following environment variables to connect to an Active Directory server:

Name Description
ADTEST_SERVER Hostname or IP Address of an Active Directory server
ADTEST_PORT Port to use - defaults to 389
ADTEST_BIND_UPN userPrincipalName ([email protected]) of admin user
ADTEST_BIND_PASS Password of admin user
ADTEST_BIND_SECURITY NONE || TLS || STARTTLS || INSECURETLS || INSECURESTARTTLS - defaults to STARTTLS
ADTEST_BASEDN LDAP Base DN - for testing the root DN is recommended, e.g. DC=example,DC=com
ADTEST_PASSWORD_UPN userPrincipalName of a test user that will be used to test password changing functions

Nested Groups

Since v3.1.0, AuthenticateExtended and Conn.ObjectGroups will automatically search for nested groups. For example, if User A is a member of Group A, and Group A is a member of Group B, using Conn.ObjectGroups on User A will return both Group A and Group B.

Security

SQL Injection is a well known attack vector, and most SQL libraries provide mitigations such as prepared statements. Similarly, LDAP Injection, while not seen often in the wild, is something we should be concerned with.

Since v2.2.0, this library sanitizes inputs (with ldap.EscapeFilter) that are used to create LDAP filters in library functions, namely GetDN and GetAttributes. This means high level functions in this library are protected against malicious inputs. If you use Search or SearchOne, take care to sanitize any untrusted inputs you use in your LDAP filter.

More Repositories

1

hassio-apcupsd

An apcupsd Hass.io add-on
Shell
50
star
2

ubuntu-pxe

So you want to build an Ubuntu PXE image? You've come to the right place.
Shell
28
star
3

pygvoicelib

A python google voice library
C
25
star
4

python-google-transcribe

Simple voice to speech transcription using Google
Python
22
star
5

OpenVPN-Client-Generator

An OpenVPN utility to create client bundles.
Python
20
star
6

ipnetgen

IP subnet iterator for Go
Go
19
star
7

hassio-caddy

An Caddy Hass.io add-on
Shell
16
star
8

OldBrowserDetector

Javascript code that tells your users to upgrade their old browsers
JavaScript
10
star
9

hassio-node-red

An Node-RED Hass.io add-on (Deprecated)
Shell
9
star
10

munki-server

Server for hosting a Munki repository and dynamically generating manifests
Go
9
star
11

micromdm-scripts

Useful scripts for managing MicroMDM
Shell
8
star
12

OpenVPNWebGUI

A web interface to generate OpenVPN certificates
PHP
8
star
13

go-onvif

Simple low-level SOAP/ONVIF Go library
Go
7
star
14

eml2html

Go library and command line tool to convert eml files to html
Go
7
star
15

munki-disclaim

A munki shim for macOS's TCC
Python
7
star
16

dep-webview-oidc

A Go library and server for DEP's configuration_web_url
Go
5
star
17

pdf-splitter

Simple utility to split a PDF file into separate pages.
Go
4
star
18

go-macos-pkg

Generate and sign macOS Distribution packages from Go
Go
4
star
19

hasura-ad-webhook

An Active Directory / Hasura GraphQL Engine webhook server
Go
3
star
20

dovecot-checkpassword-ldap

Python script for Dovecot's Checkpassword interface for AD ldap
Python
3
star
21

printer-manager-cups

A CUPS client for printer-manager
Go
3
star
22

url-shortener-client

An authenticated URL Shortener
Vue
2
star
23

macserial

A small go library to get an Apple Computer's Serial Number
Go
2
star
24

dovecot-antispam-daemon

A simple daemon that combines sa-learn and dovecot-antispam
JavaScript
2
star
25

KLogViewer

A simple web interface to view user defined logs.
PHP
2
star
26

vue-directory

A searchable school staff directory built with Vue and Vuetify
Vue
2
star
27

go-adm

Go tools for working with Apple's Device Management schemas
Go
2
star
28

WebKiosk

Files to create a locked down Kisok Environment
Vala
2
star
29

PiCommand

Proof of Concept Raspberry Pi Web-Based Control Panel
Python
2
star
30

rt-docker

Opinionated Docker containers for Request Tracker.
Perl
2
star
31

securetoken

A simple, encrypted, and authenticated token
Go
2
star
32

url-shortener-server

An authenticated URL Shortener
Go
2
star
33

docker-cups-gcp

CUPS and Google Cloud Print Connector running on Docker
Dockerfile
2
star
34

mbox

Go library to parse RFC 4155 "default" mbox files
Go
2
star
35

fleetapns

A utility to get an signed APNS request like mdmctl mdmcert.download
Go
1
star
36

munki-manifest-manager

YAML-based dynamic Munki Manifests
Go
1
star
37

pyInventory

Inventory Web Interface written for web2py
HTML
1
star
38

net-monitor-pinger

Network monitoring backend service
Go
1
star
39

vue-material-boilerplate

An opinionated Vue app template
JavaScript
1
star
40

device-inventory

A Custom Inventory system written in Python
Python
1
star
41

pyURLShortener

Simple uWSGI app that shortens URLs
Python
1
star
42

ibossreg

Python iBoss Registration Agent
Python
1
star
43

hass-mqtt-govee

Use Govee Water Leak sensors with Home Assistant's MQTT Auto Discovery
Go
1
star
44

adventofcode

My attempt at the Advent of Code
Python
1
star
45

go-icmpv4

A Go package for working with ICMPv4
Go
1
star
46

printer-manager

Manage user printer permissions
Go
1
star
47

go-plugin-test

Go
1
star
48

macos-device-attestation

Go library to help build a macOS device attestation service.
Go
1
star
49

nginx-swarm

Automatic Docker Swarm NGINX proxy
Go
1
star
50

chrome_icons

repo to generate and host ChromeOS website icons
HTML
1
star
51

go-face-detect

Go library to detect faces in images and convert them to portraits
JavaScript
1
star
52

fileenv

Use Docker secrets with Twelve-Factor Apps
Go
1
star
53

go-nsurlsession

NSURLSession as http.RoundTripper
Objective-C
1
star
54

python-challenge

My try at the Python Challenge
Python
1
star