Documentation ¶
Index ¶
- Constants
- Variables
- func CreateToken(hID interface{}, encrypt bool) (string, error)
- func JWT(key []byte) echo.MiddlewareFunc
- func JWTParse(auth string, config JWTConfig) (*jwt.Token, error)
- func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc
- func WillTokenExpire(expAt int64) bool
- type API
- type Client
- type JWTConfig
- type Register
- type UserToken
Constants ¶
View Source
const (
AlgorithmHS256 = "HS256"
)
Algorithims
Variables ¶
View Source
var ( // DefaultJWTConfig is the default JWT auth middleware config. DefaultJWTConfig = JWTConfig{ Skipper: func(c echo.Context) bool { return false }, SigningMethod: AlgorithmHS256, ContextKey: "user", TokenLookup: "header:" + echo.HeaderAuthorization, } )
Functions ¶
func CreateToken ¶
CreateToken creates a jwt token with a ID
func JWT ¶
func JWT(key []byte) echo.MiddlewareFunc
JWT returns a JSON Web Token (JWT) auth middleware.
For valid token, it sets the user in context and calls next handler. For invalid token, it sends "401 - Unauthorized" response. For empty or invalid `Authorization` header, it sends "400 - Bad Request".
func JWTWithConfig ¶
func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc
JWTWithConfig returns a JWT auth middleware from config. See: `JWT()`.
func WillTokenExpire ¶
WillTokenExpire checks if a token will expire the current range is 5-30 minutes
Types ¶
type API ¶
API holds all related api handlers
func (*API) Middleware ¶
func (a *API) Middleware(isTest bool) func(echo.HandlerFunc) echo.HandlerFunc
Middleware handles JWT tokens
type Client ¶
type Client struct { gorm.Model FirstName string `gorm:"first_name" json:"first_name,omitempty"` LastName string `gorm:"last_name" json:"last_name,omitempty"` Email string `gorm:"email" json:"email,omitempty"` Secret string `gorm:"secret" json:"secret,omitempty"` }
Client is the struct that holds client information
type JWTConfig ¶
type JWTConfig struct { // Skipper defines a function to skip middleware. Skipper middleware.Skipper // Signing key to validate token. // Required. SigningKey []byte `json:"signing_key"` // Signing method, used to check token signing method. // Optional. Default value HS256. SigningMethod string `json:"signing_method"` // Context key to store user information from the token into context. // Optional. Default value "user". ContextKey string `json:"context_key"` // 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>" TokenLookup string `json:"token_lookup"` }
JWTConfig defines the config for JWT middleware.
type Register ¶
type Register struct { FirstName string `json:"first_name" valid:"alphanum,length(2|100),required"` LastName string `json:"last_name" valid:"alphanum,length(2|100),required"` Email string `json:"email" valid:"email,length(6|255),required"` Secret string `json:"password" valid:"length(6|255),required"` Admin bool `json:"admin,omitempty"` }
Register handles post requests to register a new user account
type UserToken ¶
type UserToken struct { UID string `json:"id"` jwt.StandardClaims }
Click to show internal directories.
Click to hide internal directories.