auth

package
v0.3.2-beta Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultInvoiceLookupTimeout is the default maximum time we wait for
	// an invoice update to arrive.
	DefaultInvoiceLookupTimeout = 3 * time.Second
)
View Source
const Subsystem = "AUTH"

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type Authenticator

type Authenticator interface {
	// Accept returns whether or not the header successfully authenticates
	// the user to a given backend service.
	Accept(*http.Header, string) bool

	// FreshChallengeHeader returns a header containing a challenge for the
	// user to complete.
	FreshChallengeHeader(*http.Request, string, int64) (http.Header, error)
}

Authenticator is the generic interface for validating client headers and returning new challenge headers.

type InvoiceChecker

type InvoiceChecker interface {
	// VerifyInvoiceStatus checks that an invoice identified by a payment
	// hash has the desired status. To make sure we don't fail while the
	// invoice update is still on its way, we try several times until either
	// the desired status is set or the given timeout is reached.
	VerifyInvoiceStatus(lntypes.Hash, lnrpc.Invoice_InvoiceState,
		time.Duration) error
}

InvoiceChecker is an entity that is able to check the status of an invoice, particularly whether it's been paid or not.

type L402Authenticator

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

L402Authenticator is an authenticator that uses the L402 protocol to authenticate requests.

func NewL402Authenticator

func NewL402Authenticator(minter Minter,
	checker InvoiceChecker) *L402Authenticator

NewL402Authenticator creates a new authenticator that authenticates requests based on L402 tokens.

func (*L402Authenticator) Accept

func (l *L402Authenticator) Accept(header *http.Header, serviceName string) bool

Accept returns whether or not the header successfully authenticates the user to a given backend service.

NOTE: This is part of the Authenticator interface.

func (*L402Authenticator) FreshChallengeHeader

func (l *L402Authenticator) FreshChallengeHeader(r *http.Request,
	serviceName string, servicePrice int64) (http.Header, error)

FreshChallengeHeader returns a header containing a challenge for the user to complete.

NOTE: This is part of the Authenticator interface.

type Level

type Level string
const (
	// LevelOff is the default level where no authentication is required.
	LevelOff Level = "off"
)

func (Level) FreebieCount

func (l Level) FreebieCount() freebie.Count

func (Level) IsFreebie

func (l Level) IsFreebie() bool

func (Level) IsOff

func (l Level) IsOff() bool

func (Level) IsOn

func (l Level) IsOn() bool

type Minter

type Minter interface {
	// MintL402 mints a new L402 for the target services.
	MintL402(context.Context, ...l402.Service) (*macaroon.Macaroon, string, error)

	// VerifyL402 attempts to verify an L402 with the given parameters.
	VerifyL402(context.Context, *mint.VerificationParams) error
}

Minter is an entity that is able to mint and verify L402s for a set of services.

type MockAuthenticator

type MockAuthenticator struct{}

MockAuthenticator is a mock implementation of the authenticator.

func NewMockAuthenticator

func NewMockAuthenticator() *MockAuthenticator

NewMockAuthenticator returns a new MockAuthenticator instance.

func (MockAuthenticator) Accept

func (a MockAuthenticator) Accept(header *http.Header, _ string) bool

Accept returns whether or not the header successfully authenticates the user to a given backend service.

func (MockAuthenticator) FreshChallengeHeader

func (a MockAuthenticator) FreshChallengeHeader(r *http.Request,
	_ string, _ int64) (http.Header, error)

FreshChallengeHeader returns a header containing a challenge for the user to complete.

Jump to

Keyboard shortcuts

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