map_auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 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{
        util.Must(New(
            WithAuthenticator(util.Must(
                map_auth.New(map_auth.WithAuths(map[string]string{
                    "user0": "pass0",
                    "user1": "pass1",
                })))),
            WithRealm("testrealm"))),
    },
    http.HandlerFunc(util.DummyHandler),
)

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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