Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Callback function that should perform the authentication of the user based on userID and // password. Must return true on success, false on failure. Required. // Option return user id, if so, user id will be stored in Claim Array. Authenticator func(userID string, password string) (string, bool) Unauthorized func(w http.ResponseWriter, r *http.Request, err error) // Callback function that should perform the authorization of the authenticated user. Called // only after an authentication success. Must return true on success, false on failure. // Optional, default to success. Authorizator func(userID string, w http.ResponseWriter, r *http.Request) bool // Duration that a jwt token is valid. Optional, defaults to one hour. Timeout time.Duration // Secret key used for signing. Required. Secret []byte // signing algorithm - possible values are HS256, HS384, HS512 // Optional, default is HS256. SigningAlgorithm string // TokenLookup is a string in the form of "<source>:<name>" that is used // to extract token from the request. // Optional. Default value "header:Authorization". // Possible values: // - "header:<name>" // - "query:<name>" // - "cookie:<name>" TokenLookup string // This field allows clients to refresh their token until MaxRefresh has passed. // Note that clients can refresh their token in the last moment of MaxRefresh. // This means that the maximum validity timespan for a token is MaxRefresh + Timeout. // Optional, defaults to 0 meaning not refreshable. MaxRefresh time.Duration }
Config struct
func NewConfig ¶
func NewConfig(cred config.Credentials) Config
type Handler ¶
type Handler struct {
Config Config
}
Handler struct
func (*Handler) Login ¶
func (j *Handler) Login() http.HandlerFunc
Login can be used by clients to get a jwt token. Payload needs to be json in the form of {"username": "USERNAME", "password": "PASSWORD"}. Reply will be of the form {"token": "TOKEN"}.
func (*Handler) Refresh ¶
func (j *Handler) Refresh() http.HandlerFunc
type Login ¶
type Login struct { Username string `form:"username" json:"username" binding:"required"` Password string `form:"password" json:"password" binding:"required"` }
Login form structure.
type Middleware ¶
type Middleware struct {
Config Config
}
func NewMiddleware ¶
func NewMiddleware(config Config) *Middleware
Click to show internal directories.
Click to hide internal directories.