basic

package
v0.0.27 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) (*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.

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) AddPaths added in v0.0.27

func (m *MiddlewareBuilder) AddPaths(pathPatterns []string) *MiddlewareBuilder

AddPaths compiles the provided path patterns into regular expressions and adds them to the MiddlewareBuilder. This method allows specifying which paths the middleware should apply to. Parameters: - pathPatterns: a slice of strings representing the path patterns to be added. Returns: - the pointer to the MiddlewareBuilder instance to allow method chaining.

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.

func (*MiddlewareBuilder) RefuseHTTPS added in v0.0.27

func (m *MiddlewareBuilder) RefuseHTTPS() *MiddlewareBuilder

RefuseHTTPS configures the MiddlewareBuilder to not require HTTPS for connections. This can be helpful in environments where HTTPS is not available or necessary. It sets the IsHTTPS field of MiddlewareBuilder to false. Returns: - the pointer to the MiddlewareBuilder instance to allow method chaining.

Jump to

Keyboard shortcuts

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