Documentation ¶
Overview ¶
Package jwt provides JWT Auth handlers.
Index ¶
Constants ¶
const ( // DefaultExpirationTime is the default JWT expiration time. DefaultExpirationTime = 5 * time.Minute // DefaultRenewTime is the default time before the JWT expiration when the renewal is allowed. DefaultRenewTime = 30 * time.Second // DefaultAuthorizationHeader is the default authorization header name. DefaultAuthorizationHeader = "Authorization" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct { Username string `json:"username"` jwt.StandardClaims }
Claims holds the JWT information to be encoded.
type Credentials ¶
Credentials holds the user name and password from the request body.
type JWT ¶
type JWT struct {
// contains filtered or unexported fields
}
JWT represents an instance of the HTTP retrier.
func New ¶
func New(key []byte, userHashFn UserHashFn, opts ...Option) (*JWT, error)
New creates a new instance.
func (*JWT) IsAuthorized ¶
IsAuthorized checks if the user is authorized via JWT token.
func (*JWT) LoginHandler ¶
func (c *JWT) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler handles the login endpoint.
func (*JWT) RenewHandler ¶
func (c *JWT) RenewHandler(w http.ResponseWriter, r *http.Request)
RenewHandler handles the JWT renewal endpoint.
type Option ¶
type Option func(c *JWT)
Option is the interface that allows to set the options.
func WithAuthorizationHeader ¶
WithAuthorizationHeader sets the authorization header name.
func WithExpirationTime ¶
WithExpirationTime set the JWT expiration time.
func WithRenewTime ¶
WithRenewTime set the time before the JWT expiration when the renewal is allowed.
func WithSendResponseFn ¶
func WithSendResponseFn(sendResponseFn SendResponseFn) Option
WithSendResponseFn set the function used to send back the HTTP responses.
func WithSigningMethod ¶
func WithSigningMethod(signingMethod SigningMethod) Option
WithSigningMethod sets the signing method function.
type SendResponseFn ¶
SendResponseFn is the type of function used to send back the HTTP responses.
type SigningMethod ¶
type SigningMethod jwt.SigningMethod
SigningMethod is a type alias for the Signing Method interface.
type UserHashFn ¶
UserHashFn is the type of function used to retrieve the password hash associated with each user. The hash values should be generated via bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost).