auth

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: BSD-3-Clause Imports: 4 Imported by: 7

README

Authentication

Build Status Coverage Status GoDoc Go Report Card Release

This package provides multiple authenticators and middleware for authenticating a user.

Usage

See example.

Credit

Inspired by Yii Auth.

Documentation

Index

Constants

View Source
const IdentityKey contextKey = 1

IdentityKey is the context key of identity.

Variables

View Source
var (
	ErrNoCredentials      = errors.New("no credentials provided")
	ErrInvalidCredentials = errors.New("invalid credentials")
)

Errors

Functions

func NewMiddleware added in v0.3.0

func NewMiddleware(authenticator Authenticator) func(http.Handler) http.Handler

NewMiddleware returns a middleware with the given authenticator.

Types

type Authenticator

type Authenticator interface {
	// Authenticates the current user.
	Authenticate(*http.Request, http.ResponseWriter) (Identity, error)

	// Challenge generates challenges upon authentication failure.
	Challenge(*http.Request, http.ResponseWriter)
}

Authenticator is an interface that authenticates an user.

type Identity

type Identity interface {
	GetID() string
}

Identity is an interface that should be implemented by an user instance.

func GetIdentity added in v0.3.0

func GetIdentity(ctx context.Context) Identity

GetIdentity retrieves the identity from context.

type IdentityStore

type IdentityStore interface {
	// Gets identity by ID.
	GetIdentity(id string) (Identity, error)

	// Gets identity by the given token and token type.
	GetIdentityByToken(token, tokenType string) (Identity, error)
}

IdentityStore is a store interface for retrieving identity by ID or token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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