auth

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: BSD-3-Clause Imports: 4 Imported by: 4

README

Authentication

Build Status Coverage Status Go.Dev reference Go Report Card Release Sourcegraph

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

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

func GetIdentity(ctx context.Context) Identity

GetIdentity retrieves the identity from context.

type IdentityStore

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

	// Gets identity by the given token and token type.
	GetIdentityByToken(ctx context.Context, 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