Documentation
¶
Index ¶
- Variables
- func GetGuardMiddleware(auths []GuardAuthenticator) func(c *web.C, h http.Handler) http.Handler
- type AnonymousAuthenticator
- func (a *AnonymousAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
- func (a *AnonymousAuthenticator) CreateAuthenticatedToken(user GuardUser) (GuardToken, error)
- func (a *AnonymousAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
- func (a *AnonymousAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
- func (a *AnonymousAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
- func (a *AnonymousAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
- type CookieExtractor
- type DefaultGuardToken
- type DefaultGuardUser
- type GuardAuthenticator
- type GuardManager
- type GuardToken
- type GuardUser
- type JwtLoginGuardAuthenticator
- func (a *JwtLoginGuardAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
- func (a *JwtLoginGuardAuthenticator) CreateAuthenticatedToken(user GuardUser) (GuardToken, error)
- func (a *JwtLoginGuardAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
- func (a *JwtLoginGuardAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
- func (a *JwtLoginGuardAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
- func (a *JwtLoginGuardAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
- type JwtTokenGuardAuthenticator
- func (a *JwtTokenGuardAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
- func (a *JwtTokenGuardAuthenticator) CreateAuthenticatedToken(user GuardUser) (GuardToken, error)
- func (a *JwtTokenGuardAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
- func (a *JwtTokenGuardAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
- func (a *JwtTokenGuardAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
- func (a *JwtTokenGuardAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
- type MockedAuthenticator
- func (m *MockedAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
- func (m *MockedAuthenticator) CreateAuthenticatedToken(u GuardUser) (GuardToken, error)
- func (m *MockedAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
- func (m *MockedAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
- func (m *MockedAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
- func (m *MockedAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
- type MockedManager
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidCredentialsFormat = errors.New("invalid credentials format") ErrInvalidCredentials = errors.New("invalid credentials") ErrUnableRetrieveUser = errors.New("unable to retrieve the user") ErrCredentialMismatch = errors.New("credential mismatch") ErrAuthenticatedTokenCreation = errors.New("unable to create authentication token") ErrTokenExpired = errors.New("token expired") )
View Source
var OAuth2Extractor = &request.MultiExtractor{ &CookieExtractor{ CookieName: "access_token", }, request.AuthorizationHeaderExtractor, request.ArgumentExtractor{"access_token"}, }
Extractor for OAuth2 access tokens. Looks in 'Authorization' header then 'access_token' argument for a token.
Functions ¶
func GetGuardMiddleware ¶
Types ¶
type AnonymousAuthenticator ¶
type AnonymousAuthenticator struct {
DefaultRoles []string
}
func (*AnonymousAuthenticator) CheckCredentials ¶
func (a *AnonymousAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
func (*AnonymousAuthenticator) CreateAuthenticatedToken ¶
func (a *AnonymousAuthenticator) CreateAuthenticatedToken(user GuardUser) (GuardToken, error)
func (*AnonymousAuthenticator) GetCredentials ¶
func (a *AnonymousAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
func (*AnonymousAuthenticator) GetUser ¶
func (a *AnonymousAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
func (*AnonymousAuthenticator) OnAuthenticationFailure ¶
func (a *AnonymousAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
func (*AnonymousAuthenticator) OnAuthenticationSuccess ¶
func (a *AnonymousAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
type CookieExtractor ¶
type CookieExtractor struct {
CookieName string
}
Extract token from cookie request.
func (*CookieExtractor) ExtractToken ¶
func (e *CookieExtractor) ExtractToken(req *http.Request) (string, error)
type DefaultGuardToken ¶
Default implementation to the GuardToken
func (*DefaultGuardToken) GetRoles ¶
func (t *DefaultGuardToken) GetRoles() []string
func (*DefaultGuardToken) GetUsername ¶
func (t *DefaultGuardToken) GetUsername() string
type DefaultGuardUser ¶
func (*DefaultGuardUser) GetPassword ¶
func (u *DefaultGuardUser) GetPassword() string
func (*DefaultGuardUser) GetRoles ¶
func (u *DefaultGuardUser) GetRoles() []string
func (*DefaultGuardUser) GetUsername ¶
func (u *DefaultGuardUser) GetUsername() string
type GuardAuthenticator ¶
type GuardAuthenticator interface {
// This method is call on each request.
// If the method return nil as interface{} value, it means the authenticator
// cannot handle the request
GetCredentials(req *http.Request) (interface{}, error)
// Return the user from the credentials
GetUser(credentials interface{}) (GuardUser, error)
// Check if the provided credentials are valid for the current user
CheckCredentials(credentials interface{}, user GuardUser) error
// Return a security token related to the user
CreateAuthenticatedToken(u GuardUser) (GuardToken, error)
// Action when the authentication fail.
// On a default form login, it can be used to redirect the user to login page
// return true if the workflows must be stopped (ie, the authenticator was written
// bytes on the response. false if not.
OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
// Action when the authentication success
// On a default form login, it can be used to redirect the user to protected page
// or the homepage
// return true if the workflows must be stopped (ie, the authenticator was written
// bytes on the response. false if not.
OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
}
type GuardManager ¶
type GuardToken ¶
type GuardToken interface {
// return the current username for the current token
GetUsername() string
// return the related roles linked to the current token
GetRoles() []string
}
Bare interface to used inside a request lifecycle
type JwtLoginGuardAuthenticator ¶
type JwtLoginGuardAuthenticator struct {
EndPoint *regexp.Regexp
Manager GuardManager
Validity int64
Key []byte
Logger *log.Logger
}
this authenticator will create a JWT Token from a standard form
func (*JwtLoginGuardAuthenticator) CheckCredentials ¶
func (a *JwtLoginGuardAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
func (*JwtLoginGuardAuthenticator) CreateAuthenticatedToken ¶
func (a *JwtLoginGuardAuthenticator) CreateAuthenticatedToken(user GuardUser) (GuardToken, error)
func (*JwtLoginGuardAuthenticator) GetCredentials ¶
func (a *JwtLoginGuardAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
func (*JwtLoginGuardAuthenticator) GetUser ¶
func (a *JwtLoginGuardAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
func (*JwtLoginGuardAuthenticator) OnAuthenticationFailure ¶
func (a *JwtLoginGuardAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
func (*JwtLoginGuardAuthenticator) OnAuthenticationSuccess ¶
func (a *JwtLoginGuardAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
type JwtTokenGuardAuthenticator ¶
type JwtTokenGuardAuthenticator struct {
Apply *regexp.Regexp // url to intercept as it is a login request
Ignore []*regexp.Regexp
Manager GuardManager
Validity int64
Key []byte
Logger *log.Logger
LoginPage string // url to redirect to if the token is not valid
}
this authenticator will create a JWT Token from a standard form
func (*JwtTokenGuardAuthenticator) CheckCredentials ¶
func (a *JwtTokenGuardAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
func (*JwtTokenGuardAuthenticator) CreateAuthenticatedToken ¶
func (a *JwtTokenGuardAuthenticator) CreateAuthenticatedToken(user GuardUser) (GuardToken, error)
func (*JwtTokenGuardAuthenticator) GetCredentials ¶
func (a *JwtTokenGuardAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
func (*JwtTokenGuardAuthenticator) GetUser ¶
func (a *JwtTokenGuardAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
func (*JwtTokenGuardAuthenticator) OnAuthenticationFailure ¶
func (a *JwtTokenGuardAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
func (*JwtTokenGuardAuthenticator) OnAuthenticationSuccess ¶
func (a *JwtTokenGuardAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
type MockedAuthenticator ¶
func (*MockedAuthenticator) CheckCredentials ¶
func (m *MockedAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error
func (*MockedAuthenticator) CreateAuthenticatedToken ¶
func (m *MockedAuthenticator) CreateAuthenticatedToken(u GuardUser) (GuardToken, error)
func (*MockedAuthenticator) GetCredentials ¶
func (m *MockedAuthenticator) GetCredentials(req *http.Request) (interface{}, error)
func (*MockedAuthenticator) GetUser ¶
func (m *MockedAuthenticator) GetUser(credentials interface{}) (GuardUser, error)
func (*MockedAuthenticator) OnAuthenticationFailure ¶
func (m *MockedAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool
func (*MockedAuthenticator) OnAuthenticationSuccess ¶
func (m *MockedAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool
type MockedManager ¶
Click to show internal directories.
Click to hide internal directories.