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
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.
Click to show internal directories.
Click to hide internal directories.