basic

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MiddlewareBuilder

type MiddlewareBuilder struct {
	RequiredUserHash     []byte // Byte slice containing the hash of the user credential required for authentication.
	RequiredPasswordHash []byte // Byte slice containing the hash of the password credential required for authentication.
	Realm                string // The 'realm' is a string to be displayed to the user when authentication is required.
	// It is part of the HTTP Basic Authentication standard, to give the user a context or
	// description of what area or resource the credentials will grant access to.
	Paths []*regexp.Regexp // A slice of pointer to regular expressions. Each pattern in this slice will be used
	// to match request paths that the middleware should protect. Only requests to paths
	// that match any of these patterns will be subject to authentication checks.
	IsHTTPS bool // A boolean flag indicating whether the middleware should force the use of HTTPS.

}

MiddlewareBuilder is a struct that holds the configuration options for constructing a middleware. This configuration will eventually be used to create an instance of a middleware that performs actions like authentication checks on HTTP requests. The structure is set up in a way to be modified using MiddlewareOptions functions.

func InitMiddlewareBuilder

func InitMiddlewareBuilder(requiredUser, requiredPassword, realm string, opts ...MiddlewareOptions) (*MiddlewareBuilder, error)

InitMiddlewareBuilder is a function that initializes a new MiddlewareBuilder with hashed credentials and other provided options. It takes the required username and password for authentication, a realm for the authentication prompt, and an optional list of MiddlewareOptions functions to further customize the builder.

Parameters:

  • requiredUser: The username that will be required for authentication. It will be hashed and stored in the builder.
  • requiredPassword: The password that will be required for authentication. It will also be hashed and stored.
  • realm: A description or name for the protected area used in the authentication prompt to inform the user.
  • opts: A variadic parameter, allowing zero or more functions that conform to MiddlewareOptions to be passed in. These functions can modify the builder's properties for additional customization.

Returns: - A pointer to an initialized MiddlewareBuilder containing the hashed credentials and applied options. - An error if hashing of the provided credentials fails.

func (*MiddlewareBuilder) Build

func (m *MiddlewareBuilder) Build() mist.Middleware

Build is a method of the MiddlewareBuilder struct that constructs a Middleware function that can be used to perform Basic Authentication on incoming HTTP requests. The function checks if a request's path matches any provided patterns, if the request was made using HTTPS, and if the provided authentication credentials are valid before allowing the request to continue.

Returns: - a Middleware function that performs Basic Authentication and can be used in a middleware chain in a mist server.

type MiddlewareOptions

type MiddlewareOptions func(builder *MiddlewareBuilder)

MiddlewareOptions is a type that defines a function signature for functions that can be used to configure a MiddlewareBuilder. These functions receive a pointer to a MiddlewareBuilder instance and are used to modify its fields or set up configuration.

func WithHTTPS

func WithHTTPS(isHTTPS bool) MiddlewareOptions

WithHTTPS is a function that creates and returns a MiddlewareOptions function, which is used to configure the IsHTTPS field of a MiddlewareBuilder. This configuration function allows you to specify whether the middleware should enforce HTTPS connections.

Parameters:

  • isHTTPS: A boolean value that sets the middleware's IsHTTPS field. If true, the middleware will enforce HTTPS connections.

Returns:

  • A MiddlewareOptions function that, when called with a MiddlewareBuilder, will set its IsHTTPS field according to the value provided to WithHTTPS.

func WithPaths

func WithPaths(pathPatterns []string) MiddlewareOptions

WithPaths is a function that creates and returns a MiddlewareOptions function designed to configure the Paths field of a MiddlewareBuilder. This MiddlewareOptions function allows for specifying a list of string patterns representing the paths that the middleware should protect. Each provided string pattern is compiled into a regular expression.

Parameters:

  • pathPatterns: A slice of strings, where each string is a pattern representing a path to be protected by the middleware. These patterns will be compiled into regular expressions.

Returns:

  • A MiddlewareOptions function that, when used with a MiddlewareBuilder, sets its Paths field with the compiled regular expression patterns of the provided path patterns.

Jump to

Keyboard shortcuts

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