auth

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

README

go-ad-auth

Simple Active Directory Authentication for Go.

The API is considered stable.

GoDoc

Installing

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

Dependencies:

github.com/go-ldap/ldap

If you have any issues or questions, email the email address below, or open an issue at: https://github.com/korylprince/go-ad-auth/issues

Usage

godoc gopkg.in/korylprince/go-ad-auth.v1

Or read the source. It's pretty simple and readable.

Example:

config := &auth.Config{
	Server:   "ad.example.com",
	Port:     389,
	BaseDN:   "OU=Users,DC=example,DC=com",
	Security: auth.SecurityNone,
	Debug:    false,
}
status, err := auth.Login("kory.prince", "Super$ecret", "Domain Admins", config)
//status is true if "Super$ecret" is the password for user "kory.prince" and that user is in the "Domain Admins" group.

All other code is Copyright 2018 Kory Prince (korylprince at gmail dot com.)

This code is licensed under the same license go is licensed under (with slight modification.) If you'd like another license please email me.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Login

func Login(username, password, group string, config *Config) (bool, error)

Login will check if the given username and password authenticate correctly with server given by config. username can be in the sAMAccountName or userPrincipalName format. If group is not an empty string then Login will verify that the user is in the Active Directory Group with the Common Name group. error will be non-nil if some sort of server error occurred.

func LoginWithAttrs

func LoginWithAttrs(username, password, group string, config *Config, attrs []string) (bool, map[string][]string, error)

LoginWithAttrs will function exectly like Login, but will return a given list of attributes for the user if login is successful.

Types

type Config

type Config struct {
	Server    string
	Port      int
	BaseDN    string
	Security  SecurityType
	TLSConfig *tls.Config
	Debug     bool //debug messages are written to stdout
}

Config contains settings for connecting to an Active Directory server

func (*Config) Connect

func (c *Config) Connect() (*ldap.Conn, error)

Connect returns an open connection to an Active Directory server specified by the given config

type ConfigError

type ConfigError string

ConfigError is an error resulting from a bad Config

func (ConfigError) Error

func (c ConfigError) Error() string

type LDAPError

type LDAPError string

LDAPError is a generic LDAP error

func (LDAPError) Error

func (l LDAPError) Error() string

type SecurityType

type SecurityType int

SecurityType specifies how to connect to an Active Directory server

const (
	SecurityNone SecurityType = iota
	SecurityTLS
	SecurityStartTLS
)

Security will default to SecurityNone if not given.

Jump to

Keyboard shortcuts

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