Documentation ¶
Index ¶
Constants ¶
const ( AuthKey = "hawk_auth" UserKey = "hawk_user" )
Variables ¶
var ErrNotFound = errors.New("Credentials not found")
ErrNotFound is set in context.Err if the GetCredentialFunc returns nil
Functions ¶
func GetAuth ¶
GetAuth returns the *hawk.Auth from the context. Will panic if not set (i.e. when the filter fail or has not happend yet)
func GetUser ¶
GetUser returns the user object (obtain with the GetCredentialFunc) from the context. Will panic if not set (i.e. when the filter fail or has not happend yet)
func ISHawkError ¶
Types ¶
type AbortHandlerFunc ¶
type Credentials ¶
type Credentials struct { Key string User interface{} }
Credentials is used to store a key string and a User object. It is returned by a function of type GetCredentialFunc.
type GetCredentialFunc ¶
type GetCredentialFunc func(id string) (*Credentials, error)
GetCredentialFunc is a function that returns a *Credentials by id. If nothing is found the result should be nil and it's an authentication error (set in context). If an error occured (an external problem like db connection), return the error and it will be set as the context error.
type Middleware ¶
type Middleware struct { GetCredentials GetCredentialFunc SetNonce SetNonceFunc AbortHandler AbortHandlerFunc UserParam string Ext string }
Middleware is the middleware object. GetCredentials is the GetCredentialFunc SetNonce is the SetNonceFunc UserParam if set will set the user in the context with a matching key Ext add an "ext" header in the request
func NewMiddleware ¶
func NewMiddleware(gcf GetCredentialFunc, snf SetNonceFunc) *Middleware
NewMiddleware creates a new Middleware with the GetCredentials and SetNonce params set. UserParam is set to "user" by default.
func (*Middleware) Abortequest ¶
Abortequest aborts the request and set the context error and status. When possible it will attempt to send a "Server-Authorization" header.
func (*Middleware) Filter ¶
func (hm *Middleware) Filter(c *gin.Context)
Filter is the middleware function that validate the hawk authentication.
type Request ¶
type Request struct { Hawk *Middleware ID string User interface{} Ok bool Error error }
Request represent the state of a request.
func (*Request) CredentialsLookup ¶
func (hr *Request) CredentialsLookup(creds *hawk.Credentials) error
CredentialsLookup lookup the credantial for hawk-go from the user provided GetCredentialFunc.
func (*Request) NonceCheck ¶
NonceCheck call the SetNonceFunc on behalf of hawk-go.