package
0.0.0-20241222002135-c9d1db9af773
Repository: https://github.com/alphaone1/midgard.git
Documentation: pkg.go.dev

# README

Basic Authentication Middleware

Basic Authentication is an authentication method where the client sends its credentials unencrypted to the server for validation. This middleware implements this process. A detailed description can also be found here.

The credentials can be stored in different forms. This module has an interface for authenticators, that provide the final verification, and concentrates on the protocol between the client and the server. Further a simple example authenticator is provided that is to be configured with the allowed credentials.

Example

finalHandler := midgard.StackMiddlewareHandler(
    []midgard.Middleware{
        util.Must(basic_auth.New(
            basic_auth.WithRealm("example realm"),
            basic_auth.WithAuthenticator(util.Must(
                map_auth.New(
                    map_auth.WithAuths(map[string]string{
                        "user0": "pass0",
                        "user1": "pass1",
                    }),
                ),
            )),
        )),
    },
    http.HandlerFunc(HelloHandler),
)

If no realm is specified using WithRealm the default Restricted is used. Not providing an authenticator is an error condition.

# Packages

No description provided by the author
No description provided by the author

# Functions

ExtractUserPass extracts the username and the password out of the given header value for Authorization.
New generates a new basic authentication middleware.
WithAuthenticator sets the Authenticator to use.
WithLogger configures the logger to use.
WithLogLevel configures the log level to use with the logger.
WithRealm sets the realm to use.
No description provided by the author

# Structs

Handler holds the internal data of the basic authentication middleware.

# Interfaces

Authenticator is an interface the basic auth handler uses to check if the given credentials match an allowed entry.