mapauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MPL-2.0 Imports: 1 Imported by: 0

README

Map Authorizer

The map authorizer is a simple user-password matcher. It is configured inside the program. It is, next to "always true", one of the most simple authorizers possible.

Example

handler := midgard.StackMiddlewareHandler(
    []defs.Middleware{
        helper.Must(basicauth.New(
            basicauth.WithAuthenticator(helper.Must(
                mapauth.New(mapauth.WithAuths(map[string]string{
                    "user0": "pass0",
                    "user1": "pass1",
                })))),
            basicauth.WithRealm("testrealm"))),
    },
    http.HandlerFunc(helper.DummyHandler),
)

Be aware that writing credentials inside program code is not advisable and is just used here to illustrate the usage.

Documentation

Overview

Package mapauth implements the basic auth functionality using a user-pass-map.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAuthorizations = errors.New("no authorizations configured")

ErrNoAuthorizations is returned when no authorizations are configured.

View Source
var ErrNotInitialized = errors.New("mapauth not initialized")

ErrNotInitialized is returned when the map authenticator is not initialized.

Functions

func WithAuths

func WithAuths(auths map[string]string) func(a *MapAuthenticator) error

WithAuths sets the allowed username-password combinations.

Types

type MapAuthenticator

type MapAuthenticator struct {
	// contains filtered or unexported fields
}

MapAuthenticator holds the authentication relevant data.

func New

func New(options ...func(a *MapAuthenticator) error) (*MapAuthenticator, error)

New creates a new MapAuthenticator with the given configuration.

func (*MapAuthenticator) Authenticate

func (a *MapAuthenticator) Authenticate(username, password string) (bool, error)

Authenticate checks if a given username has the given password entry identical in the internal auths map.

Jump to

Keyboard shortcuts

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