login

package
v0.0.0-...-01c0304 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ContentTypeHtml = "text/html; charset=utf-8"
View Source
const ContentTypeJWT = "application/jwt"
View Source
const ContentTypePlain = "text/plain"
View Source
const SimpleProviderName = "simple"

Variables

This section is empty.

Functions

func RegisterProvider

func RegisterProvider(desc *ProviderDescription, factoryMethod Provider)

RegisterProvider registers a factory method by the provider name.

Types

type Backend

type Backend interface {
	// Authenticate checks the username/password against the backend.
	// On success it returns true and a UserInfo object which has at least the username set.
	// If the credentials do not match, false is returned.
	// The error parameter is nil, unless a communication error with the backend occured.
	Authenticate(username, password string) (bool, UserInfo, error)
}

func SimpleBackendFactory

func SimpleBackendFactory(config map[string]string) (Backend, error)

type BackendOptions

type BackendOptions []map[string]string

func (*BackendOptions) Set

func (bo *BackendOptions) Set(value string) error

func (*BackendOptions) String

func (bo *BackendOptions) String() string

type Config

type Config struct {
	Host           string `env:"LOGINSRV_HOST"`
	Port           string `env:"LOGINSRV_PORT"`
	LogLevel       string `env:"LOGINSRV_LOG_LEVEL"`
	TextLogging    bool   `env:"LOGINSRV_TEXT_LOGGING"`
	JwtSecret      string `env:"LOGINSRV_JWT_SECRET"`
	SuccessUrl     string `env:"LOGINSRV_SUCCESS_URL"`
	CookieName     string `env:"LOGINSRV_COOKIE_NAME"`
	CookieHttpOnly bool   `env:"LOGINSRV_COOKIE_HTTP_ONLY"`
	Backends       BackendOptions
}
var DefaultConfig Config

func ReadConfig

func ReadConfig() *Config

type Handler

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

func NewHandler

func NewHandler(config *Config) (*Handler, error)

NewHandler creates a login handler based on the supplied configuration.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Provider

type Provider func(config map[string]string) (Backend, error)

Provider is a factory method for creation of login backends.

func GetProvider

func GetProvider(providerName string) (Provider, bool)

GetProvider returns a registered provider by its name. The bool return parameter indicated, if there was such a provider.

type ProviderDescription

type ProviderDescription struct {
	// the name of the provider
	Name string
	// contains filtered or unexported fields
}

type ProviderOption

type ProviderOption struct {
	Name        string
	Description string
	Default     string
	Required    string
}

type SimpleBackend

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

Simple backend, working on a map of username password pairs

func NewSimpleBackend

func NewSimpleBackend(userPassword map[string]string) *SimpleBackend

NewSimpleBackend creates a new SIMPLE Backend and verifies the parameters.

func (*SimpleBackend) Authenticate

func (sb *SimpleBackend) Authenticate(username, password string) (bool, UserInfo, error)

type UserInfo

type UserInfo struct {
	Username string `json:"sub"`
}

func (UserInfo) Valid

func (u UserInfo) Valid() error

this interface implementation lets us use the user info as Claim for jwt-go

Jump to

Keyboard shortcuts

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