auth

package
v0.0.0-...-73b4bbd Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package auth provides a stream processing pattern to supply user authentication to a filu application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticatedUser

type AuthenticatedUser struct {
	filu.Time
	Request
}

An AuthenticatedUser is the result of a correct Username & Password combonation.

type CreatedUser

type CreatedUser struct {
	filu.Time
	Request
}

A CreatedUser is the result of a Request where the user doesn't already exist.

type InvalidPassword

type InvalidPassword struct {
	filu.Time
	Request
}

An InvalidPassword is the result of a Request with an invalid password.

type Processor

type Processor interface {
	RequestConsumer
	ResultProducer
	// contains filtered or unexported methods
}

A Processor is the step in a Stream when a Request is transformed into a Result. This is where a Username/Password pair would be compared against what exists in a database to determine if the pair is a valid.

func NewProcessor

func NewProcessor(from io.Reader) (Processor, error)

NewProcessor reads gob encoded Requests from io.Reader and apply them to the processors state in order.

type Request

type Request struct {
	filu.Time
	Username, Password string

	// The public interface for the user to receive the
	// result of the authentication request.
	InvalidPassword   <-chan InvalidPassword
	CreatedUser       <-chan CreatedUser
	AuthenticatedUser <-chan AuthenticatedUser
	// contains filtered or unexported fields
}

A Request is a filu.Event that represents an authentication request sent by a client/user. It is consumed by a Processor that will output a PostAuthEvent.

func NewRequest

func NewRequest(username, password string) Request

NewRequest will construct a Request suitible for use with Stream.RequestAuthentication() <- Request.

func (Request) Close

func (r Request) Close()

Close the response channels. Should be called after a response has been received, else a send on a closed channel may trigger a panic.

type RequestConsumer

type RequestConsumer interface {
	// The implementation of Write can assume in will never be called in parallel.
	Write(Request)
}

A RequestConsumer is used as the consumption end of a RequestStream.

type RequestProducer

type RequestProducer interface {
	Read() <-chan Request
}

A RequestProducer is used as the production end of a RequestStream.

type RequestStream

type RequestStream interface {
	RequestConsumer
	RequestProducer
}

A RequestStream represents a function that when given a Request will produce a Request.

func NewRequestStream

func NewRequestStream(streams ...RequestStream) RequestStream

NewRequestStream will concatenate a series of RequestStreams into a single RequestStream. The Consumer entry point will be the first parameter, the Producer endpoint will be the last parameter.

type Result

type Result interface {
	filu.Event
	// contains filtered or unexported methods
}

A Result of a Request after it was processed by a Processor.

type ResultConsumer

type ResultConsumer interface {
	// The implementation of Write can assume in will never be called in parallel.
	Write(Result)
}

A ResultConsumer is a sink of a stream of Results.

type ResultProducer

type ResultProducer interface {
	Read() <-chan Result
}

A ResultProducer is the source of a stream of Results.

type ResultStream

type ResultStream interface {
	ResultProducer
	ResultConsumer
}

A ResultStream is sink & source of Results. It is implemented and used when constructing a Stream to hook into the post-auth Result stream for user defined processing.

func NewResultStream

func NewResultStream(streams ...ResultStream) ResultStream

NewResultStream will concatenate a series of ResultStreams into a single ResultStream. The Consumer entry point will be the first parameter, the Producer endpoint will be the last parameter.

type Stream

type Stream interface {
	RequestAuthentication() chan<- Request
}

A Stream consumes Request's.

func NewStream

func NewStream(preAuth RequestStream, processor Processor, postAuth ResultStream) Stream

NewStream creates an auth processor and connect the Result output into the provided ResultStream's and returns a terminated Stream that will return the Result of a Request back to the Requestor.

Jump to

Keyboard shortcuts

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