Categorygithub.com/vogtp/go-basic-auth
modulepackage
0.2.4
Repository: https://github.com/vogtp/go-basic-auth.git
Documentation: pkg.go.dev

# README

go-basic-auth GocodecovGo Report CardReleaseGoDoc

A go module for simple HTTP basic auth.

Currently a LDAP backend and a simple in memory backend is provided.

package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
	auth "github.com/vogtp/go-basic-auth"
)

func main() {
	allowMap := make(map[string]string)
	allowMap["user"] = "password"
	basicAuth := auth.New(
		auth.WithInMemory(allowMap),                            // authorise users in allowMap (no groups used)
		auth.WithLdap("SERVER_NAME", "BASE_DN", "DOMAIN_NAME"), // authorise users for (AD) LDAP
		auth.WithGroup("group"),                                // One or more groups the user has to be in to be authorised
		auth.Debug(),                                           // enable debug output
		auth.WithFailMsg("Use the email address as user name")) // custom error message
	// use as http middleware
	http.HandleFunc("/", basicAuth.Handler(http.NotFound))
	// or use as GIN middleware
	gin := gin.Default()
	gin.Use(basicAuth.Gin())
}

# Packages

No description provided by the author

# Functions

Debug forces for log output.
New creates a new BasicAuth authenticator with sever and base DN user must be in one of the authGroups to be successfully authenticated.
WithBackend sets a authentication backend.
WithFailMsg sets a custom message on auth failure.
WithGroup sets groups that the user has to be in to be authorised.
WithInMemory is a convience function to add a in memory authentication.
WithLdap is a convience function to add a LDAP server.

# Structs

Backend provides basic HTTP Auth against a AuthBackend.

# Interfaces

Authenticator provides handler funcs.
Backender defines the interface to the auth backends.

# Type aliases

Option is a func to configure basic auth.